<jupyter_start><jupyter_text>At least we know that the model works... This feature set includes Goals for Home and Goals for Away which respectively have a weighting of 1 and -1 for the end result of Goal Difference. Now to do the same but remove these features.<jupyter_code>features = ['Position_Home', 'Points_Home', 'Total_Wins_Home',
       'Total_Draw_Home', 'Total_Lose_Home', 'Total_Goals_For_Home_Team',
       'Total_Goals_Against_Home_Team', 'Total_Streak_Home', 'Wins_When_Home',
       'Draw_When_Home', 'Lose_When_Home', 'Goals_For_When_Home',
       'Goals_Against_When_Home', 'Position_Away', 'Points_Away',
       'Total_Wins_Away', 'Total_Draw_Away', 'Total_Lose_Away',
       'Total_Goals_For_Away_Team', 'Total_Goals_Against_Away_Team',
       'Total_Streak_Away', 'Wins_When_Away', 'Draw_When_Away',
       'Lose_When_Away', 'Goals_For_When_Away', 'Goals_Against_When_Away',
       'Streak_When_Home', 'Streak_When_Away',]
X = np.array(combined_csv[features])
y = np.array(combined_csv['difference'])
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=4)
model = LinearRegression()
model.fit(X_train, y_train)
b = model.intercept_
m = model.coef_
print(m, b)
model.score(X_train, y_train)<jupyter_output><empty_output><jupyter_text>Assessing the features and their weights, as determined by the model.<jupyter_code>weights = list(zip(features, m**2))
weights_df = df = pd.DataFrame(weights, columns = ['Feature', 'Weight_sq'])
weights_df.sort_values(by=['Weight_sq'])<jupyter_output><empty_output><jupyter_text>Let us try to normalize the data beforehand and view the results.<jupyter_code>from sklearn import preprocessing
X_normalized = preprocessing.normalize(X, axis=0)
X
X_normalized[1100]
X_train, X_test, y_train, y_test = train_test_split(X_normalized, y, test_size=0.2, random_state=4)
model = LinearRegression()
model.fit(X_train, y_train)
b = model.intercept_
m = model.coef_
print(m, b)
model.score(X_train, y_train)
X_mod = np.round(model.predict(X_test))
result_mod = X_mod - y_test
len(result_mod[np.where(result_mod == 0)])/len(X_mod)

for i, num in enumerate(result_mod):
    if num > 1:
        result_mod[i] = 1
    elif num < -1:
        result_mod[i] = -1
len(result_mod[np.where(result_mod == 0)])/len(X_mod)
        
model.predict(X_test)
model.score(X_mod, y_test)
X_train[12]
weights = list(zip(features, m**2))
weights_df = df = pd.DataFrame(weights, columns = ['Feature', 'Weight_sq'])
weights_df.sort_values(by=['Weight_sq'])
X[0]
combined_csv.to_csv( "combined_clean.csv", index=False, encoding='utf-8-sig')
combined_csv[combined_csv["Round"]>20][features]
def lin_reg(X, y):
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=4)
    model = LinearRegression()
    model.fit(X_train, y_train)
    b = model.intercept_
    m = model.coef_
    return (m, b, model.score(X_train, y_train))

linear_reg_dict = {}

for i in range(30):
    X = np.array(combined_csv[combined_csv["Round"]>i][features])
    y = np.array(combined_csv[combined_csv["Round"]>i]['difference'])
    linear_reg_dict[i] = lin_reg(X, y)
linear_reg_dict
feature_weights_dict = {}
m_values = []
model_score = []
for feat in features:
    feature_weights_dict[feat] = []

for j, _ in enumerate(list(linear_reg_dict.values())):
    for i, feat in enumerate(list(linear_reg_dict.values())[j][0]):
        feature_weights_dict[features[i]].append(feat)
    m_values.append(list(linear_reg_dict.values())[j][1])
    model_score.append(list(linear_reg_dict.values())[j][2])
    
print(feature_weights_dict)    
print(m_values)
print(mode_score)
rounds = [x+1 for x in range(30)]
rounds
feat_df = pd.DataFrame(feature_weights_dict)
feat_df
feat_df["model_score"] = model_score
feat_df["m_value"] = m_values
feat_df
feat_df[feat_df.columns[0]]
%matplotlib inline
fig, axs = plt.subplots(len(feat_df.columns),figsize=(10, 150))
fig.suptitle('Varying Scores when squeezing the data towards Season end')
for i, ax in enumerate(axs):
    ax.plot(rounds, feat_df[feat_df.columns[i]])
    ax.set_title(feat_df.columns[i])
    
plt.show()


features_plus = ['Round','Position_Home', 'Points_Home', 'Total_Wins_Home',
       'Total_Draw_Home', 'Total_Lose_Home', 'Total_Goals_For_Home_Team',
       'Total_Goals_Against_Home_Team', 'Total_Streak_Home', 'Wins_When_Home',
       'Draw_When_Home', 'Lose_When_Home', 'Goals_For_When_Home',
       'Goals_Against_When_Home', 'Position_Away', 'Points_Away',
       'Total_Wins_Away', 'Total_Draw_Away', 'Total_Lose_Away',
       'Total_Goals_For_Away_Team', 'Total_Goals_Against_Away_Team',
       'Total_Streak_Away', 'Wins_When_Away', 'Draw_When_Away',
       'Lose_When_Away', 'Goals_For_When_Away', 'Goals_Against_When_Away',
       'Streak_When_Home', 'Streak_When_Away',]
X = np.array(combined_csv[features_plus])
y = np.array(combined_csv['difference'])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=4)
model = LinearRegression()
model.fit(X_train, y_train)
b = model.intercept_
m = model.coef_
print (m, b, model.score(X_train, y_train))
from sklearn.linear_model import SGDRegressor

features = ['Position_Home', 'Points_Home', 'Total_Wins_Home',
       'Total_Draw_Home', 'Total_Lose_Home', 'Total_Goals_For_Home_Team',
       'Total_Goals_Against_Home_Team', 'Total_Streak_Home', 'Wins_When_Home',
       'Draw_When_Home', 'Lose_When_Home', 'Goals_For_When_Home',
       'Goals_Against_When_Home', 'Position_Away', 'Points_Away',
       'Total_Wins_Away', 'Total_Draw_Away', 'Total_Lose_Away',
       'Total_Goals_For_Away_Team', 'Total_Goals_Against_Away_Team',
       'Total_Streak_Away', 'Wins_When_Away', 'Draw_When_Away',
       'Lose_When_Away', 'Goals_For_When_Away', 'Goals_Against_When_Away',
       'Streak_When_Home', 'Streak_When_Away',]
X = np.array(combined_csv[features])
y = np.array(combined_csv['difference'])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=4)
model = SGDRegressor(max_iter=1000, tol=1e-3)
model.fit(X_train, y_train)
b = model.intercept_
m = model.coef_
print (m, b, model.score(X_train, y_train))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13510448728333063, 'fraction_numerical': 0.009071764134132512, 'mean_word_length': 6.096551724137931, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 17, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '666340', 'license': 'MIT', 'n_tokens_mistral': 2463, 'n_tokens_neox': 2414, 'n_words': 411, 'path': 'Untitled.ipynb', 'repo_name': 'TamimEhsan2021/AiBetCore', 'size': '6173'}