AI demo framework

import pickle
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import cross_val_score
from sklearn import metrics

iris = datasets.load_iris()
X_train,X_test,y_train,y_test = train_test_split(iris.data, iris.target, test_size=0.3)

k_range = range(1,31)
k_score = []
for k in k_range:
    knn = KNeighborsClassifier(n_neighbors=k)
    scores = cross_val_score(knn, X_train, y_train, cv=10, scoring=‘accuracy’)
    k_score.append(scores.mean())

plt.figure()
plt.plot(k_range, k_score)
plt.xlabel(‘Value of k for KNN’)
plt.ylabel(‘CrossValidation accuracy’)
plt.show()

max_score = max(k_score)
print("max score:", max_score)
best_k = k_range[k_score.index(max_score)]
knn = KNeighborsClassifier(n_neighbors=best_k)
knn.fit(X_train, y_train)
y_predict = knn.predict(X_test)
print("test data accuracy:", metrics.accuracy_score(y_test, y_predict))
print("classification report:
", metrics.classification_report(y_test, y_predict))

with open("knn.pkl", "wb") as f:
    pickle.dump(knn, f)

import pickle
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import cross_val_score
from sklearn import metrics

iris = datasets.load_iris()
X_train,X_test,y_train,y_test = train_test_split(iris.data, iris.target, test_size=0.3)

k_range = range(1,31)
k_score = []
for k in k_range:
    knn = KNeighborsClassifier(n_neighbors=k)
    scores = cross_val_score(knn, X_train, y_train, cv=10, scoring=‘accuracy’)
    k_score.append(scores.mean())

plt.figure()
plt.plot(k_range, k_score)
plt.xlabel(‘Value of k for KNN’)
plt.ylabel(‘CrossValidation accuracy’)
plt.show()

max_score = max(k_score)
print("max score:", max_score)
best_k = k_range[k_score.index(max_score)]
knn = KNeighborsClassifier(n_neighbors=best_k)
knn.fit(X_train, y_train)
y_predict = knn.predict(X_test)
print("test data accuracy:", metrics.accuracy_score(y_test, y_predict))
print("classification report:
", metrics.classification_report(y_test, y_predict))

with open("knn.pkl", "wb") as f:
    pickle.dump(knn, f)

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 436 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.