How do I work with data using a Machine Learning Model? Jupyter Notebook, pandas, scikit-learn

Publié le: 18 juin 2024
sur la chaîne: Mentor Junior Java Developer
89
0

How do I work with data using a Machine Learning Model? I will show how to use the ML Model to predict whether the patient has heart disease or not based on the medical records available for free on the internet.

1. Components required
1.1. Development environment
1.2. Source code
1.3. Tools
1.4. Creating a project
2. Machine Learning Workflow
3. Working with the data
3.1. Importing the tools
3.2. Loading the data
3.3. Split the data into features and labels
3.4. Split the data into training and test sets
4. Using Machine Learning Model/Algorithm/Estimator
4.1. RandomForestClassifier – Supervised ML
4.2. Training the ML Model
4.3. Predicting values with ML Model
5. Data characteristics

We want to train the ML Model on the training data so it’s going to learn the patterns, the relationship between the X variables, features, and the y variable, labels – indicates whether the patient has heart disease (1) or no heart disease (0). The ML Model aka algorithm or estimator is a black box where the Machine Learning magic goes.

In Machine Learning, one of the most fundamental principles is never to evaluate or test models on data that it is learned from, which is why we split it into training and test sets. It’s like looking at the final exam before we’ve looked at the practice exam, not what we want to be doing! If the professor accidentally leaked the final exam, everyone would be getting perfect marks and no one would be learning anything.

0:00 Introduction, showcase
1:33 What's covered
1:55 Create and set up a project - Conda
4:04 What is Machine Learning?
4:43 Install Data Science tools
5:52 Project setup recap
6:25 Jupyter Notebook
7:50 Machine Learning Workflow
8:48 Getting the patient's data - Kaggle
9:15 The dataset overview
10:40 Importing the tools - Jupyter
11:55 Loading the data - pandas
13:25 Split data - features and labels
15:50 Split data - training & test set
19:43 np.random.seed(42)
20:20 Machine Learning Model
21:41 Training the ML Model - fit()
22:51 Predicting values using ML Model
23:55 Combine predictions with test data
25:30 Data characteristics
26:00 What was covered
27:09 Thanks!

#machinelearning #machinelearningwithpython #python #jupyternotebook #conda #pandas #scikitlearn #datascience #machinelearningmodel

Importing the tools
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sklearn

Setup random seed - to have the same results, me and you
np.random.seed(42)

Get the data with medical records from Kaggle
Load the .data file into a DataFrame
heart_disease = pd.read_csv('data/heart-disease_kaggle.csv')

X - training input samples, features
X = heart_disease.drop("target", axis=1)

y - training input labels, the desired result, the target value
y = heart_disease["target"]

Import 'train_test_split()' function
"Split arrays or matrices into random train and test subsets."
from sklearn.model_selection import train_test_split

Split the data into training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

Import the RandomForestClassifier estimator class
from sklearn.ensemble import RandomForestClassifier

Instantiate RandomForestClassifier
model = RandomForestClassifier()

'fit()' - Build a forest of trees from the training set (X, y).
model.fit(X_train, y_train)

'predict()' - Predict class for X.
y_preds = model.predict(X_test)

Now what we’ve done is we’ve made predictions on the Test Data Set to predict whether a patient has or not a heart disease.


Sur cette page du site, vous pouvez voir la vidéo en ligne How do I work with data using a Machine Learning Model? Jupyter Notebook, pandas, scikit-learn durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Mentor Junior Java Developer 18 juin 2024, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 89 fois et il a aimé 0 téléspectateurs. Bon visionnage!