# Using a trained Model from Pickle

I trained and saved a model that should predict a sons hight based on his fathers height. I then saved the model to Pickle. I can now load the model and want to use it but unfortunately a second variable is demanded from me (besides the height of the father) I think I did something wrong when training the model?

I will post the part of the code wher I think the error is in, please ask if you need more.

#Spliting the data into test and train data
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)

#Doing a linear regression
lm=LinearRegression()
lm.fit(X_train,y_train)

#testing the model with an example value
TestValue = 65.0
filename = 'Father_Son_Height_Model.pckl'
print(result)


The error message says:

ValueError: Expected 2D array, got scalar array instead:

array=65.0.

Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

You need to use loaded_model.predict(TestValue), not loaded_model.score(TestValue). The latter is for evaluating the models accuracy, and you would also need to pass the true height of the son, which is the y value it's asking for.
• @G.M this is scikit-learn being a bit annoying. It needs an array in a specific shape or it won't work. Try loaded_model.predict(np.array(TestValue).reshape(-1, 1)). skl is a great package but it could be more robust to this kind of thing. Make sure to include import numpy as np somewhere – Dan Scally Sep 20 '19 at 7:29