How to use Regression Metrics in Python?
MACHINE LEARNING RECIPES DATA CLEANING PYTHON DATA MUNGING PANDAS CHEATSHEET     ALL TAGS

# How to use Regression Metrics in Python?

This recipe helps you use Regression Metrics in Python

0
This python source code does the following: 1. Imports all the necessary library 2. Applyies Decisiontreemodel on the dataset 3. Performs CrossValidation for better result 4. Evaluates the final result using "neg_mean_squared_error" ,"neg_absolute_error" and "r2" metrics
In :
```## How to use Regression Metrics in Python
def Snippet_182():
print()
print(format('How to use Regression Metrics in Python','*^82'))
import warnings
warnings.filterwarnings("ignore")

from sklearn import datasets
from sklearn import tree, model_selection
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt

plt.style.use('ggplot')

seed = 42
X = dataset.data; y = dataset.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
kfold = model_selection.KFold(n_splits=10, random_state=seed)
# fit a tree.DecisionTreeClassifier() model to the data
model = tree.DecisionTreeRegressor()

# metrics -> Mean Absolute Error
scoring = 'neg_mean_absolute_error'
results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
print(); print("Mean Absolute Error: ", results.mean()); print("Standard Deviation: ", results.std())

# metrics -> Mean Squred Error
scoring = 'neg_mean_squared_error'
results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
print(); print("Mean Squared Error: ", results.mean()); print("Standard Deviation: ", results.std())

# metrics -> R squared
scoring = 'r2'
results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)
print(); print("R squared val: ", results.mean()); print("Standard Deviation: ", results.std())
Snippet_182()
```
```*********************How to use Regression Metrics in Python**********************

Mean Absolute Error:  -3.0952560455192035
Standard Deviation:  0.4539146116435922

Mean Squared Error:  -21.0677652916074
Standard Deviation:  9.255250927975112

R squared val:  0.7561802285707946
Standard Deviation:  0.1692887494698974
```

#### Relevant Projects

##### Predict Census Income using Deep Learning Models
In this project, we are going to work on Deep Learning using H2O to predict Census income.

##### Identifying Product Bundles from Sales Data Using R Language
In this data science project in R, we are going to talk about subjective segmentation which is a clustering technique to find out product bundles in sales data.

##### Human Activity Recognition Using Smartphones Data Set
In this deep learning project, you will build a classification system where to precisely identify human fitness activities.

##### Customer Churn Prediction Analysis using Ensemble Techniques
In this machine learning churn project, we implement a churn prediction model in python using ensemble techniques.

##### Ecommerce product reviews - Pairwise ranking and sentiment analysis
This project analyzes a dataset containing ecommerce product reviews. The goal is to use machine learning models to perform sentiment analysis on product reviews and rank them based on relevance. Reviews play a key role in product recommendation systems.

##### Predict Credit Default | Give Me Some Credit Kaggle
In this data science project, you will predict borrowers chance of defaulting on credit loans by building a credit score prediction model.

##### Music Recommendation System Project using Python and R
Machine Learning Project - Work with KKBOX's Music Recommendation System dataset to build the best music recommendation engine.

##### Learn to prepare data for your next machine learning project
Text data requires special preparation before you can start using it for any machine learning project.In this ML project, you will learn about applying Machine Learning models to create classifiers and learn how to make sense of textual data.

##### Machine Learning or Predictive Models in IoT - Energy Prediction Use Case
In this machine learning and IoT project, we are going to test out the experimental data using various predictive models and train the models and break the energy usage.

##### Build an Image Classifier for Plant Species Identification
In this machine learning project, we will use binary leaf images and extracted features, including shape, margin, and texture to accurately identify plant species using different benchmark classification techniques.