<jupyter_start><jupyter_text>Hands-On Data Preprocessing in PythonLearn how to effectively prepare data for successful data analytics        AUTHOR: Dr. <NAME>  Chapter 6: Prediction<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import numpy as np<jupyter_output><empty_output><jupyter_text>Predictive models Forecasting Example of using forecasting to predict future<jupyter_code>msu_df = pd.read_csv('MSU applications.csv')
msu_df.set_index('Year',drop=True,inplace=True)
application_df = pd.DataFrame(msu_df.N_Applications)
application_df.transpose()
plt.figure(figsize=(7,3))
plt.plot(application_df)
plt.xticks(application_df.index,rotation=90)
plt.show()
application_df.loc[2017:2021].mean()
average_df = pd.DataFrame(application_df.loc[2017:2021])
average_df['N_Applications'] = 15901.2
average_df.loc[2022] = 15901.2
predict_df = pd.DataFrame(application_df.loc[2021]).transpose()
predict_df.loc[2022] = 15901.2
predict_df
plt.figure(figsize=(7,3))
plt.plot(application_df)
plt.plot(average_df,linestyle='--',c='C1')
plt.plot(predict_df,c='C1')
plt.xticks(application_df.index,rotation=90)
plt.show()<jupyter_output><empty_output><jupyter_text>Regression Analysis Example of designing regression analysis to predict future values Linear Regression<jupyter_code>import pandas as pd
msu_df = pd.read_csv('MSU applications.csv')
msu_df.set_index('Year',drop=True,inplace=True)
msu_df
conda install -c intel scikit-learn
from sklearn.linear_model import LinearRegression

X = ['P_Football_Performance','SMAn2']
y = 'N_Applications'

data_X = msu_df[X]
data_y = msu_df[y]

lm = LinearRegression()
lm.fit(data_X, data_y)

print('intercept (b0) ', lm.intercept_)
coef_names = ['b1','b2']
print(pd.DataFrame({'Predictor': data_X.columns,
                    'coefficient Name':coef_names, 
                    'coefficient Value': lm.coef_}))<jupyter_output>intercept (b0)  -890.7106225983407
                Predictor coefficient Name  coefficient Value
0  P_Football_Performance               b1        5544.961933
1                   SMAn2               b2           0.907032<jupyter_text>How to use the trained equation for prediction<jupyter_code>newData = pd.DataFrame({'P_Football_Performance':0.364,'SMAn2':17198},
                       index=[2022])
newData
lm.predict(newData)<jupyter_output><empty_output><jupyter_text>Multi-Layered Perceptron (MLP)<jupyter_code>from sklearn.neural_network import MLPRegressor

X = ['P_Football_Performance','SMAn2']
y = 'N_Applications'

data_X = msu_df[X]
data_y = msu_df[y]

mlp = MLPRegressor(hidden_layer_sizes=6, max_iter=10000)
mlp.fit(data_X, data_y)

mlp.predict(newData)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11588785046728972, 'fraction_numerical': 0.045233644859813085, 'mean_word_length': 5.5911330049261085, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '627063', 'license': 'MIT', 'n_tokens_mistral': 1066, 'n_tokens_neox': 954, 'n_words': 166, 'path': 'Chapter06/Chapter 6.ipynb', 'repo_name': 'arifmudi/Hands-On-Data-Preprocessing-in-Python-', 'size': '2679'}