Lab 3-ML
Lab 3-ML
We'll use the Random Forest Classifier for the classification task. Random
Forest is an ensemble learning method that creates multiple decision trees and
combines their results to make predictions. It is robust and works well for both
Steps:
Example Code:
We'll use the Iris dataset, a popular classification dataset, where we predict the
confusion_matrix
iris = load_iris()
X = iris.data # features (sepal length, sepal width, petal length, petal width)
random_state=42)
# Step 3: Initialize the Random Forest Classifier model
rf_model.fit(X_train, y_train)
y_pred = rf_model.predict(X_test)
print(f"Accuracy: {accuracy:.2f}")
Explanation:
sklearn.datasets. The dataset contains 150 samples of iris flowers, and each
sample has 4 features (sepal length, sepal width, petal length, and petal
width).
2. Data Preprocessing: We split the dataset into training and testing sets using
analysis.
2. Regression Algorithm: Random Forest Regressor
Next, let's use Random Forest Regressor for a regression task. Random Forest
Regressor works similarly to the Random Forest Classifier but for continuous
target variables. It builds multiple decision trees and averages their predictions.
Steps:
Example Code:
We'll use the Boston housing dataset, which contains information about various
boston = load_boston()
random_state=42)
rf_regressor.fit(X_train, y_train)
y_pred = rf_regressor.predict(X_test)
r2 = r2_score(y_test, y_pred)
print(f"R-squared: {r2:.2f}")
Explanation:
1. Loading Data: We load the Boston housing dataset using load_boston() from
features (such as crime rate, average number of rooms, etc.), and the target is
2. Data Preprocessing: We split the dataset into training and testing sets (70%
4. Model Evaluation: We evaluate the model using the Mean Squared Error
(MSE), which measures the average squared difference between the actual
and predicted values. We also use R-squared (R²), which tells us how well
the model explains the variance in the data (a value close to 1 means a good
fit).
Build Auto AI model in Watson
IBM Watson AutoAI is a tool that allows users to automate the process of building,
platform that performs tasks such as data preprocessing, model selection, and
hyperparameter tuning automatically. This makes it a great tool for both novice and
experienced data scientists who want to quickly create and deploy machine
learning models.
Studio.
Before using IBM Watson AutoAI, you need an IBM Cloud account and access to
o Once logged in, you can access the tools for building AutoAI models.
Once you have access to IBM Watson Studio, follow these steps to create a new
project.
o Go to the IBM Watson Studio dashboard and sign in with your IBM
Cloud credentials.
2. Create a New Project:
o Choose the project name, description, and a location for your project.
o Click Create.
Before building an AutoAI model, you need data. You can upload a dataset to
2. Choose "Data" and upload a CSV file or a dataset from a public repository.
o For example, you can use the Iris dataset, Titanic dataset, or any other
tabular dataset that you want to use for training the model.
o Once uploaded, the data will appear in the "Data" section of the
project.
Now you can create the AutoAI experiment to automatically build a model.
regression
Feature selection: Identifying the most relevant features for model training.
You don’t need to manually perform these steps, as AutoAI handles them during
the experiment.
After preprocessing the data, AutoAI automatically runs several models and selects
XGBoost, Neural Networks, etc.) to automatically choose the best one for
your task.
Once the AutoAI experiment finishes running, you can view a Model Performance
o You can view performance details like accuracy, precision, recall, F1-