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 ra…


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


This content originally appeared on DEV Community and was authored by Durga Pokharel


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline." Durga Pokharel | Sciencx - Wednesday April 7, 2021, https://www.scien.cx/2021/04/07/day-99-of-100daysofcodecentering-and-scaling-in-a-pipeline/
HARVARD
Durga Pokharel | Sciencx Wednesday April 7, 2021 » Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline., viewed ,<https://www.scien.cx/2021/04/07/day-99-of-100daysofcodecentering-and-scaling-in-a-pipeline/>
VANCOUVER
Durga Pokharel | Sciencx - » Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/04/07/day-99-of-100daysofcodecentering-and-scaling-in-a-pipeline/
CHICAGO
" » Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline." Durga Pokharel | Sciencx - Accessed . https://www.scien.cx/2021/04/07/day-99-of-100daysofcodecentering-and-scaling-in-a-pipeline/
IEEE
" » Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline." Durga Pokharel | Sciencx [Online]. Available: https://www.scien.cx/2021/04/07/day-99-of-100daysofcodecentering-and-scaling-in-a-pipeline/. [Accessed: ]
rf:citation
» Day 99 Of 100DaysOfCode:Centering and scaling in a pipeline | Durga Pokharel | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.