DEV Community

Cover image for Predicting Divorces Pronounced In Mauritius Using Linear Regression (ML)
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer

Posted on

Predicting Divorces Pronounced In Mauritius Using Linear Regression (ML)

here is a post about linear regression, the first step of machine learning. we'll be using python to predict divorce cases for mauritius, my country

What Is Linear Regression

regression just means prediction.

read more on those two dev.to articles

Our Data

we'll be downloading our csv from here . the first one. i renamed it divorce.csv

Opening Up Jupyter

let us import our libs

import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
# psst inspect sklearn to see what other models there are
Enter fullscreen mode Exit fullscreen mode

let's have a look at our data

df = pd.read_csv('<path-to-file>/divorce.csv')
df
Enter fullscreen mode Exit fullscreen mode

gives us

Alt text of image

we'll be predicting the column Number of cases disposed of which Divorce pronounced

but let us have a look at our data

plt.scatter(df['Year'], df['Number of cases disposed of which Divorce pronounced'])
Enter fullscreen mode Exit fullscreen mode

we get

Alt text of image

let us train our model

reg = linear_model.LinearRegression()
reg.fit(df[['Year']], df['Number of cases disposed of which Divorce pronounced'])
Enter fullscreen mode Exit fullscreen mode

and predict for the year 2017

reg.predict([[2017]])# it was 1,921
Enter fullscreen mode Exit fullscreen mode

we get

array([ 2140.22222222])
Enter fullscreen mode Exit fullscreen mode

Getting m And c

since linear regression is just a straight line (really that whole machine learning world is just some maths), we can get the coefficient (our m) and the intercept (our c)

coefficient is given by

reg.coef_
Enter fullscreen mode Exit fullscreen mode

outputs

array([ 57.79118774])
Enter fullscreen mode Exit fullscreen mode

and intercept by

reg.intercept_
Enter fullscreen mode Exit fullscreen mode

outputs

-114424.60344827584
Enter fullscreen mode Exit fullscreen mode

Building Our Own Predictor Function

we can now build a simple function to predict without passing by ml

def devdotto_predict(year_):
    # m * x + c
    return 57.79118774 * year_ + -114424.60344827584
Enter fullscreen mode Exit fullscreen mode

and use it

devdotto_predict(2017)
Enter fullscreen mode Exit fullscreen mode

we get

2140.222223304154
Enter fullscreen mode Exit fullscreen mode

compare above

Conclusion

machine learning is super easy if you understand the concept!

cover img credit : Photo by Xavier Coiffic On Unsplash
real pic of mauritius

Top comments (3)

Collapse
 
edwew32 profile image
agsa asf

The Florida Child Support Calculator is a valuable tool designed to help parents estimate the amount of child support that may be required under Florida law. This calculator provides a clear and structured method for determining child support obligations, taking into account various essential factors such as each parent’s income, the number of children, healthcare and childcare expenses, and the time each parent spends with the children. By inputting accurate financial and custodial information how far behind in child support before a warrant is issued in florida, the tool can generate a reliable estimate that aligns with the Florida Child Support Guidelines, giving parents a better understanding of their legal responsibilities and rights.

Collapse
 
aleen_m_5eac43ea296275cf1 profile image
Aleen M

Predicting divorces in Mauritius using linear regression means analyzing past data to find trends and factors affecting divorce rates. This machine learning method helps forecast future divorces based on things like the economy and social changes. Although focused on Mauritius, studying divorcio en Florida can provide useful insights since both places may share similar social patterns, improving the prediction model’s accuracy.

Collapse
 
abdurrahmaanj profile image
Abdur-Rahmaan Janhangeer

The Simplest It Can Get!