Challenge

Supervised Learning - Classification Week 8 Challenge

1. Apply knn to the “Surface defects in stainless steel plates” and identify the differences

pipe_df=pd.read_csv('faults.csv')
X=pipe_df.iloc[:,:-1]
y=pipe_df['Other_Faults']

# Splitting the dataset into training and test set.
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test= train_test_split(X, y, test_size= 0.25, random_state=0)

classifier = KNeighborsClassifier(n_neighbors=5, metric='minkowski', p=2 )
clf_fit=classifier.fit(x_train, y_train)
kn_scores=clf_fit.score(x_test, y_test)
y_pred=clf_fit.predict(x_test)

print('\nclassification_report\n',classification_report(y_test, y_pred))

classification_report
               precision    recall  f1-score   support

           0       0.99      0.98      0.98       324
           1       0.96      0.98      0.97       162

    accuracy                           0.98       486
   macro avg       0.97      0.98      0.98       486
weighted avg       0.98      0.98      0.98       486

2 . What are the pros and cons of knn

Advantages :
new data can be added , Simple algorithm , good for large dataset

Disadvantages:

slow , doesn't work well with high dimension , sensitive to outlier, noise , need value of K for better accuracy
Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.