Train/test split + accuracy निकालना
अब churn_df डेटासेट के साथ अपने डेटा को training और test सेट में बाँटने का अभ्यास कीजिए!
आपके लिए NumPy arrays बना दिए गए हैं जिनमें फीचर्स X में हैं और target वैरिएबल y में है.
यह अभ्यास पाठ्यक्रम का हिस्सा है
scikit-learn के साथ Supervised Learning
अभ्यास निर्देश
sklearn.model_selectionसेtrain_test_splitइम्पोर्ट करें.Xऔरyको training और test सेट में बाँटें, जहाँtest_size20% हो,random_state42हो, और target लेबल के अनुपात मूल डेटासेट जैसे बने रहें.knnमॉडल को training डेटा पर फिट करें.- test डेटा के लिए मॉडल की accuracy compute करके प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
# Import the module
from ____ import ____
X = churn_df.drop("churn", axis=1).values
y = churn_df["churn"].values
# Split into training and test sets
X_train, X_test, y_train, y_test = ____(____, ____, test_size=____, random_state=____, stratify=____)
knn = KNeighborsClassifier(n_neighbors=5)
# Fit the classifier to the training data
____
# Print the accuracy
print(knn.score(____, ____))