with open("model.pkl","wb") as f:
pickle.dump(model,f)
with open("model.pkl","rb") as f:
mp = pickle.load(f)
mp.predict([[X_test_sample]])
model = pickle.load(open('model.pkl','rb'))
print(model.predict([[X_test_sample]]))
I couldn't fetch my model into flask or joblib because I am getting the below error
ValueError Traceback (most recent call last)
in
----> 1 jm.predict([[1,50,30000,50000,40000]])
~\Anaconda3\lib\site-packages\keras\engine\training.py in predict(self, x, batch_size, verbose, steps, callbacks, max_queue_size, workers, use_multiprocessing)
1439
1440 # Case 2: Symbolic tensors or Numpy array-like.
-> 1441 x, _, _ = self._standardize_user_data(x)
1442 if self.stateful:
1443 if x[0].shape[0] > batch_size and x[0].shape[0] % batch_size != 0:
~\Anaconda3\lib\site-packages\keras\engine\training.py in _standardize_user_data(self, x, y, sample_weight, class_weight, check_array_lengths, batch_size)
577 feed_input_shapes,
578 check_batch_axis=False, # Don't enforce the batch size.
--> 579 exception_prefix='input')
580
581 if y is not None:
~\Anaconda3\lib\site-packages\keras\engine\training_utils.py in standardize_input_data(data, names, shapes, check_batch_axis, exception_prefix)
143 ': expected ' + names[i] + ' to have shape ' +
144 str(shape) + ' but got array with shape ' +
--> 145 str(data_shape))
146 return data
147
ValueError: Error when checking input: expected dense_1_input to have the shape (5,) but got array with shape (1,)
**Could anyone please help me in deploying this model..!!**
@Sanjusree8
Hi, this issue is not related to TurtleBot3 so I'll close it.
You might get more feedback from developers in other machine learning communities.
import pandas as pd import numpy as np import pickle
import matplotlib.pyplot as plt
car_df = pd.read_csv("Car_Purchasing_Data.csv",encoding = 'ISO-8859-1')
X = car_df.drop (['Customer Name','Customer e-mail','Country','Car Purchase Amount'],axis = 1) y = car_df['Car Purchase Amount']
from sklearn.preprocessing import MinMaxScaler
scaler_x = MinMaxScaler() X_scaled = scaler_x.fit_transform(X)
y = y.values.reshape(-1,1)
scaler_y = MinMaxScaler()
y_scaled = scaler_y.fit_transform(y)
from sklearn.model_selection import train_test_split X_train,X_test,y_train,y_test = train_test_split(X_scaled,y_scaled,test_size = 0.25)
import tensorflow.keras from Keras.models import Sequential from Keras. layers import Dense from sklearn. preprocessing import MinMaxScaler
model = Sequential() model.add(Dense(25,input_dim = 5,activation='relu')) model.add(Dense(25,input_dim = 5 ,activation = 'relu')) model.add(Dense(1,activation ='linear')) model.summary()
model.compile(optimizer = 'adam',loss='mean_squared_error')
epochs_hist = model.fit(X_train,y_train,epochs=10,batch_size=25,verbose =1,validation_split = 0.2)
X_test_sample = np.array([[1, 55, 300000, 400000, 300500]]) y_predict_sample = model.predict(X_test_sample) print('Expected Purchase Amount',y_predict_sample)
with open("model.pkl","wb") as f: pickle.dump(model,f)
with open("model.pkl","rb") as f: mp = pickle.load(f)
mp.predict([[X_test_sample]]) model = pickle.load(open('model.pkl','rb'))
print(model.predict([[X_test_sample]]))
I couldn't fetch my model into flask or joblib because I am getting the below error
ValueError Traceback (most recent call last)