Issue
I trained a model using the following code
import pandas as pd
from sklearn.model_selection import train_test_split
data = pd.read_csv('sampledata.csv')
cols_to_use = ['OUNdif', 'UFMdif', 'Class']
X = data[cols_to_use]
y = data.W
X_train, X_valid, y_train, y_valid = train_test_split(X, y)
from xgboost import XGBClassifier
my_model = XGBClassifier(n_estimators=1000, learning_rate=0.05)
my_model.fit(X_train, y_train,
early_stopping_rounds=5,
eval_set=[(X_valid, y_valid)],
verbose=False)
from sklearn.metrics import accuracy_score
predictions = my_model.predict(X_valid)
Now if I were to add a new row to the bottom (#355), how would I use my now trained model to predict just that row? (Without accidentally using it as part of the training data)
Solution
You can pass as a list your OUNdif, UFMdif, Class
ie: [6, 5, 25]
Then predict the value from an np array with just this line and get the first element of the prediction.
input_to_guess = [6,5,25]
print(my_model.predict(np.array(input_to_guess).reshape((1, -1)))[0])
It should return the value you want
Answered By - Tristan LG
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.