0
$\begingroup$

I'm working with data(with 4 columns which are p(product), M(name of the store)), I want predict the demand of store for that I sued SVR on the data by theses formulation:

dfn = pd.get_dummies(df)
x = dfn.drop(["demand"],axis=1)
y = dfn.demand
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler(feature_range=(0,1))
dfn = scaler.fit_transform(dfn)
.
.
.
from sklearn.metrics import r2_score
pred = regressor.predict(testX)
SVM_R2 = print('r2= ' +str(r2_score(testY,pred)))
print(pred)
# array example is between 0 and 1
array = np.array(pred)
#scaled from 200 to 800
minimo = 200
maximo = 800
output=array * minimo + (maximo - minimo)
print(output)
df2=pd.DataFrame(output)
df2.to_excel(r'/content/Book1.xlsx', index = False)

and now I get the output of this prediction. My question is, how can I match these outputs to inputs, or how can I found which demands are related to each market?

enter image description here

enter image description here

enter image description here

$\endgroup$
0
$\begingroup$

The outputs of your model are in the same order as your inputs, so the first row in your output array corresponds to the first row in the testX array. If you want to have both the inputs and the model prediction in one table you can just concatenate them along the column axis.

$\endgroup$
1
  • $\begingroup$ I can't use this, because if you look at the pictures which I attached, you find that the size of data after using is different from the main (when split into train and test sets). $\endgroup$ – ramin Feb 21 at 19:02
0
$\begingroup$

I used this code and get output from this(with the help of Oxbowerce).

df2=pd.DataFrame(testX,columns=['p','M','Date'])
df3=pd.DataFrame(pred,columns=['pred'])
df4=pd.concat([df2,df3],axis=1)
df4.to_excel(r'/content/Book1.xlsx', index = False)

I saved the output in an excel file. You can see in the below picture.

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.