<jupyter_start><jupyter_text>Load the dataset- Load the train data and using all your knowledge of pandas try to explore the different statistical properties of the dataset.<jupyter_code># read the dataset and extract the features and target separately
train = pd.read_csv('train.csv')
train
train.info()
random_key = 6
X = train[['Age','Overall','Potential','Wage (M)']]
y = train['Value (M)']

X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.3, random_state=random_key)
X_train<jupyter_output><empty_output><jupyter_text>Visualize the data- Check for the categorical & continuous features. - Check out the best plots for plotting between categorical target and continuous features and try making some inferences from these plots.- Check for the correlation between the features<jupyter_code># Code Starts here

def show_boxplot(col_data, x_label, y_label, title, fig_size=(7, 7), show_outliers=True):
    """
    Shows boxplot with means
    
    Params:
    -------
    col_data: list or numpy array
    x_label: str
    y_label: str
    title: str
    fig_size: tupe of (int, int)
    show_outliers: bool
    """
    fig = plt.figure(figsize=fig_size)
    plt.boxplot(col_data, showmeans=True, showfliers=show_outliers)
    plt.title(title, fontsize=21, color='navy')
    plt.xlabel(x_label)
    plt.ylabel(y_label)
    plt.show()

for col in X_train.select_dtypes(include=np.number).columns:
    x_label = col
    y_label = 'Distribution'
    data = X_train[col]
    title = f'Distribution for {col}'
    show_boxplot(col_data=data, x_label=x_label, y_label=y_label, title=title)
# Code ends here
sns.heatmap(X_train.corr())
upper_threshold = 0.5
lower_threshold = -0.5


# List the correlation pairs
correlation = train.corr().unstack().sort_values(kind='quicksort')

# Select the highest correlation pairs having correlation greater than upper threshold and lower than lower threshold
corr_var_list = correlation[((correlation>upper_threshold) | (correlation<lower_threshold)) & (correlation!=1)]
print(corr_var_list)<jupyter_output>Id         Overall     -0.975595
Overall    Id          -0.975595
Id         Potential   -0.653503
Potential  Id          -0.653503
Id         Value (M)   -0.548213
Value (M)  Id          -0.548213
Id         Wage (M)    -0.519570
Wage (M)   Id          -0.519570
Potential  Wage (M)     0.512910
Wage (M)   Potential    0.512910
Overall    Wage (M)     0.589736
Wage (M)   Overall      0.589736
Potential  Value (M)    0.595095
Value (M)  Potential    0.595095
Overall    Value (M)    0.635618
Value (M)  Overall      0.635618
Overall    Potential    0.678228
Potential  Overall      0.678228
Wage (M)   Value (M)    0.845124
Value (M)  Wage (M)     0.845124
dtype: float64<jupyter_text>Model building- Separate the features and target and then split the train data into train and validation set.- Now let's come to the actual task, using linear regression, predict the `Value (M)`. - Try improving upon the `r2_score` (R-Square) using different parameters that give the best score. You can use higher degree [Polynomial Features of sklearn](https://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.PolynomialFeatures.html) to improve the model prediction.<jupyter_code># Code Starts here
linreg = LinearRegression()
logreg = LogisticRegression()
#y = np.log(y_train)

linreg.fit(X_train,y_train)
y_pred = linreg.predict(X_test)
# display predictions
print('Mean Absolute Error :',(mean_absolute_error(y_test,y_pred)))
print('R-Square :',r2_score(y_test,y_pred))
# Code ends here

print('-'*20)

#Polynomial Feature
from sklearn.preprocessing import PolynomialFeatures

poly = PolynomialFeatures(4)
X_train_2 = poly.fit_transform(X_train)
X_test_2 = poly.transform(X_test)

model = LinearRegression()
model.fit(X_train_2, y_train)

y_pred_2 = model.predict(X_test_2)

r2 = r2_score(y_test,y_pred_2)
print("R-Square :", r2)

mae = mean_absolute_error(y_test, y_pred_2)
print('Mean Absolute Error :', mae)<jupyter_output>Mean Absolute Error : 1.36113034368551
R-Square : 0.7728182411379437
--------------------
R-Square : 0.9748469694258696
Mean Absolute Error : 0.3528900386871176<jupyter_text>Prediction on the test data and creating the sample submission file.- Load the test data and store the `Id` column in a separate variable.- Perform the same operations on the test data that you have performed on the train data.- Create the submission file as a `csv` file consisting of the `Id` column from the test data and your prediction as the second column.<jupyter_code># Code Starts here
test = pd.read_csv('test.csv')
Id = test['Id']
test = test.drop(["Name","Nationality","Club","Position",'Id'],axis=1)

test_poly = poly.transform(test)
y_pred_1 = model.predict(test_poly)
y_pred_1 = y_pred_1.flatten()
id_1=pd.DataFrame({'Id':id,'Value (M)':y_pred_1})
id_1.to_csv("submission.csv", encoding='utf-8', index=False)
# Code ends here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10866046135167948, 'fraction_numerical': 0.04917037636584379, 'mean_word_length': 4.3495670995671, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '494413', 'license': 'MIT', 'n_tokens_mistral': 1827, 'n_tokens_neox': 1668, 'n_words': 475, 'path': 'FIFA_Project_Student-Template.ipynb', 'repo_name': 'nikdalvi/fifa-project', 'size': '4942'}