I have trained and saved a model :
import numpy as np
# load the dataset
dataset = np.loadtxt("modiftrain.csv", delimiter=";")
# split into input (X) and output (Y) variables
X_train = dataset[:,0:5]
Y_train = dataset[:,5]
from sklearn.naive_bayes import GaussianNB
# create Gaussian Naive Bayes model object and train it with the data
nb_model = GaussianNB()
nb_model.fit(X_train, Y_train.ravel())
# predict values using the training data
nb_predict_train = nb_model.predict(X_train)
# import the performance metrics library
from sklearn import metrics
# Accuracy
print("Accuracy: {0:.4f}".format(metrics.accuracy_score(Y_train, nb_predict_train)))
print()
# import the lib to load / Save the model
from sklearn.externals import joblib
# Save the model
joblib.dump(nb_predict_train, "trained-model.pkl")
Then, i'm loading the model and try to make predictions on a new dataset :
# import the lib to load / Save the model
from sklearn.externals import joblib
import numpy as np
# Load the model
nb_predict_train = joblib.load("trained-model.pkl")
# load the test dataset
df_predict = np.loadtxt("modiftest.csv", delimiter=";")
X_train = df_predict
nb_predict_train.predict(X_train)
print(X_train)
Here comes the error :
File "predict01.py", line 14, in <module>
nb_predict_train.predict(X_train)
AttributeError: 'numpy.ndarray' object has no attribute 'predict'