# How to use a a trained model

I just trained my first model in Python 3.7/scikitlearn (Linear Regression) (well I copied most of the code but its something ^^).

Now I want to actually Use the model. Specifically its about sons heights incorrelating to their fathers. So I now want to enter a new Father-height and get a predictions for its sons height.

How could something like this look like?

I read about "Pickle" to save a model and use it later, seems awsome but how would I use such a saved model?

If anybody can give me a simple answer or even just a link to atutorial would be great. Below is a piece of "my" code just for some context.

#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)

#Predicting the height of Sons
y_test=lm.predict(X_test)
print(y_test)


You have your model saved as the variable lm. You can use the lm.predict(X_test) for any other test scenario. Note that your X_test should be similar to your X_train meaning if you have transformations made on your X_train, you need to do similar transformation on X_test too. You can use pickle in the following way

import pickle
filename = 'model.pckl'
pickle.dump(model, open(filename, 'wb'))

#To load the model from disk, use this