This content originally appeared on DEV Community and was authored by Durga Pokharel
This is my 99th day of #100daysofcode and #python learning journey. Approximately I am in terminal point. Now I feel I am champion. Talking about today's progress I keep learning from DataCamp. I also did some exercises there. Did some codes on the random topic.
Centering and Scaling In a Pipeline
# Import the necessary modules
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
# Setup the pipeline steps: steps
steps = [('scaler', StandardScaler()),
('knn', KNeighborsClassifier())]
# Create the pipeline: pipeline
pipeline = Pipeline(steps)
# Create train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)
# Fit the pipeline to the training set: knn_scaled
knn_scaled = pipeline.fit(X_train, y_train)
# Instantiate and fit a k-NN classifier to the unscaled data
knn_unscaled = KNeighborsClassifier().fit(X_train, y_train)
# Compute and print metrics
print('Accuracy with Scaling: {}'.format(knn_scaled.score(X_test, y_test)))
print('Accuracy without Scaling: {}'.format(knn_unscaled.score(X_test, y_test)))
The output of above code is,
Accuracy with Scaling: 0.7700680272108843
Accuracy without Scaling: 0.6979591836734694
Day 99 Of #100daysofcode and #python
— Durga Pokharel (@durgacodes) April 7, 2021
Centering and scaling in a pipeline from DataCamp
One more day to reach in a terminal point. Finally I am going to complete 100daysofcode.#100DaysOfCode #WomenWhoCode #DEVCommunity pic.twitter.com/crjxj5Fzuy
This content originally appeared on DEV Community and was authored by Durga Pokharel
Durga Pokharel | Sciencx (2021-04-07T15:51:18+00:00) Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline. Retrieved from https://www.scien.cx/2021/04/07/day-99-of-100daysofcodecentering-and-scaling-in-a-pipeline/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.