Reputation: 73
In my predicted dataframe I have three columns, I want to merge all those three columns with the original dataset. How can I achieve this?
ds = pd.read_csv("final10.csv")
X = ds.iloc[:, 3:-4].values
y = ds.iloc[:,-1].values
testcase = pd.read_csv("testcase.csv")
testcase=testcase.iloc[:,3:-1].values
from sklearn.linear_model import LogisticRegression
clf = LogisticRegression(solver="newton-cg", multi_class='multinomial')
clf.fit(X, y)
y_pred1 = clf.predict_proba(testcase)
testcase['procurement']=pd.Series(y_pred1)
The error I'm getting is "Exception: Data must be 1-dimensional"
Upvotes: 0
Views: 1221
Reputation: 36609
You are trying to assign 3 columns in y_pred1
to a single column in dataframe testcase
. Thats the source of error. You will have to use three different target columns in the dataframe to assign the three prediction columns.
So for example, if your y
has three unique classes (labels) in the data, the predict_proba()
output (y_pred1
in this case) will be of shape [n, 3]
.
You can combine this 2-d array to the existing dataframe in multiple ways:
Simple way: Assign each column separately
testcase['procurement_class0'] = y_pred1[:,0]
testcase['procurement_class1'] = y_pred1[:,1]
testcase['procurement_class2'] = y_pred1[:,2]
Other ways: Look into these questions here:
Upvotes: 1