DEV Community

Durga Pokharel
Durga Pokharel

Posted on

6

Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline

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)))
Enter fullscreen mode Exit fullscreen mode

The output of above code is,

Accuracy with Scaling: 0.7700680272108843
Accuracy without Scaling: 0.6979591836734694
Enter fullscreen mode Exit fullscreen mode

Day 99 Of #100daysofcode and #python
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

— Durga Pokharel (@durgacodes) April 7, 2021

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (1)

Collapse
 
otumianempire profile image
Michael Otu

👏

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay