Guest User

Untitled

a guest
Dec 14th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. import numpy as np
  2.  
  3. # load the dataset
  4. dataset = np.loadtxt("modiftrain.csv", delimiter=";")
  5.  
  6. # split into input (X) and output (Y) variables
  7. X_train = dataset[:,0:5]
  8. Y_train = dataset[:,5]
  9.  
  10. from sklearn.naive_bayes import GaussianNB
  11.  
  12. # create Gaussian Naive Bayes model object and train it with the data
  13. nb_model = GaussianNB()
  14.  
  15. nb_model.fit(X_train, Y_train.ravel())
  16.  
  17. # predict values using the training data
  18. nb_predict_train = nb_model.predict(X_train)
  19.  
  20. # import the performance metrics library
  21. from sklearn import metrics
  22.  
  23. # Accuracy
  24. print("Accuracy: {0:.4f}".format(metrics.accuracy_score(Y_train, nb_predict_train)))
  25. print()
  26.  
  27. # import the lib to load / Save the model
  28. from sklearn.externals import joblib
  29.  
  30. # Save the model
  31. joblib.dump(nb_predict_train, "trained-model.pkl")
  32.  
  33. # import the lib to load / Save the model
  34. from sklearn.externals import joblib
  35.  
  36. import numpy as np
  37.  
  38. # Load the model
  39. nb_predict_train = joblib.load("trained-model.pkl")
  40.  
  41. # load the test dataset
  42. df_predict = np.loadtxt("modiftest.csv", delimiter=";")
  43.  
  44. X_train = df_predict
  45.  
  46. nb_predict_train.predict(X_train)
  47.  
  48. print(X_train)
  49.  
  50. File "predict01.py", line 14, in <module>
  51. nb_predict_train.predict(X_train)
  52. AttributeError: 'numpy.ndarray' object has no attribute 'predict'
Add Comment
Please, Sign In to add comment