!pip install anvil-uplink
Requirement already satisfied: anvil-uplink in /root/venv/lib/python3.7/site-packages (0.3.34)
Requirement already satisfied: ws4py in /root/venv/lib/python3.7/site-packages (from anvil-uplink) (0.5.1)
Requirement already satisfied: argparse in /root/venv/lib/python3.7/site-packages (from anvil-uplink) (1.4.0)
Requirement already satisfied: six in /shared-libs/python3.7/py-core/lib/python3.7/site-packages (from anvil-uplink) (1.15.0)
Requirement already satisfied: future in /shared-libs/python3.7/py/lib/python3.7/site-packages (from anvil-uplink) (0.18.2)
WARNING: You are using pip version 20.1.1; however, version 21.0.1 is available.
You should consider upgrading via the '/root/venv/bin/python -m pip install --upgrade pip' command.
import anvil.server
anvil.server.connect("7DXSIWHYUGHOII53HYY3YPCL-OHXSSWLWIY6MAIQD")
Connecting to wss://anvil.works/uplink
Anvil websocket open
Connected to "Default environment (dev)" as SERVER
import matplotlib.pyplot as plt
from sklearn import metrics
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.neighbors import KNeighborsClassifier
iris = load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2 , random_state=4)
# The following code is used only when needing to find the optimal n_neighbors
"""
scores = {}
scores_list = []
k_range = range(1, 26)
for k in k_range:
knn = KNeighborsClassifier(n_neighbors=k)
knn.fit(X_train, y_train)
y_pred = knn.predict(X_test)
scores[k] = metrics.accuracy_score(y_test, y_pred)
scores_list.append(metrics.accuracy_score(y_test, y_pred))
plt.plot(k_range,scores_list)
plt.xlabel('Value of K for KNN')
plt.ylabel('Testing Accuracy')
"""
knn = KNeighborsClassifier(n_neighbors=10)
knn.fit(X,y)
@anvil.server.callable
def predict_iris(sepal_length, sepal_width, petal_length, petal_width):
classification = knn.predict([[sepal_length, sepal_width, petal_length, petal_width]])
return iris.target_names[classification][0]
anvil.server.wait_forever()
/shared-libs/python3.7/py/lib/python3.7/site-packages/sklearn/utils/validation.py:63: FutureWarning: Arrays of bytes/strings is being converted to decimal numbers if dtype='numeric'. This behavior is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). Please convert your data to numeric values explicitly instead.
return f(*args, **kwargs)
/shared-libs/python3.7/py/lib/python3.7/site-packages/sklearn/utils/validation.py:63: FutureWarning: Arrays of bytes/strings is being converted to decimal numbers if dtype='numeric'. This behavior is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). Please convert your data to numeric values explicitly instead.
return f(*args, **kwargs)
/shared-libs/python3.7/py/lib/python3.7/site-packages/sklearn/utils/validation.py:63: FutureWarning: Arrays of bytes/strings is being converted to decimal numbers if dtype='numeric'. This behavior is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). Please convert your data to numeric values explicitly instead.
return f(*args, **kwargs)
/shared-libs/python3.7/py/lib/python3.7/site-packages/sklearn/utils/validation.py:63: FutureWarning: Arrays of bytes/strings is being converted to decimal numbers if dtype='numeric'. This behavior is deprecated in 0.24 and will be removed in 1.1 (renaming of 0.26). Please convert your data to numeric values explicitly instead.
return f(*args, **kwargs)
KeyboardInterrupt: