<jupyter_start><jupyter_text>Test part<jupyter_code>dataset_test = pd.read_csv('test.csv')
dataset_test.head()
dataset_test.shape
cod_participants = dataset_test.loc[:, 'NU_INSCRICAO']
dataset_test = dataset_test.loc[:, ['NU_NOTA_CN', 'NU_NOTA_CH', 'NU_NOTA_LC', 'NU_NOTA_REDACAO' ]]
dataset_test.head()
dataset_test.shape
dataset_test['NU_NOTA_CN'].fillna(dataset_test['NU_NOTA_CN'].mean(), inplace=True)
dataset_test['NU_NOTA_CH'].fillna(dataset_test['NU_NOTA_CH'].mean(), inplace=True)
dataset_test['NU_NOTA_LC'].fillna(dataset_test['NU_NOTA_LC'].mean(), inplace=True)
dataset_test['NU_NOTA_REDACAO'].fillna(dataset_test['NU_NOTA_REDACAO'].mean(), inplace=True)
#OPTIONAL
# scaler_test = StandardScaler()
# scaler.fit(dataset_test)
# # scaled_df_test = scaler.transform(dataset_test)
# col = ['NU_NOTA_CN', 'NU_NOTA_CH', 'NU_NOTA_LC', 'NU_NOTA_REDACAO']
# dataset_test = pd.DataFrame(scaled_df_test, columns=col)
# dataset_test.head()
pred_data = decision_tree_regr.predict(dataset_test)
one_dim_pred_data = []
for i in range(len(pred_data)):
#     print(pred_data[i])
    one_dim_pred_data.append(pred_data[i][0])
    
pred_data = one_dim_pred_data
data_file = {
    'NU_INSCRICAO': cod_participants,
    'NU_NOTA_CN': dataset_test['NU_NOTA_CN'],
    'NU_NOTA_CH': dataset_test['NU_NOTA_CH'],
    'NU_NOTA_LC': dataset_test['NU_NOTA_LC'],
    'NU_NOTA_REDACAO': dataset_test['NU_NOTA_REDACAO'],
    'NU_NOTA_MT': pred_data
}

save_pred = pd.DataFrame(data_file, columns= ['NU_INSCRICAO', 'NU_NOTA_CH','NU_NOTA_LC','NU_NOTA_CN','NU_NOTA_REDACAO', 'NU_NOTA_MT'])
save_pred.head()
save_pred.to_csv('first_prediction.csv', index=False, header=True)
# weights of each part
math_weight = 3
natural_sciences_weight = 2
code_languages_weight = 1.5
human_sciences_weight = 1
essay_weight = 3

# total weights
total_weights = math_weight + natural_sciences_weight + code_languages_weight + \
+ human_sciences_weight + essay_weight

final_grades = []

# For each student calculate the weighted average
for student_index in range(save_pred.shape[0]):
    current_grade = (save_pred.loc[student_index, 'NU_NOTA_MT'] * math_weight + \
    save_pred.loc[student_index, 'NU_NOTA_CN'] * natural_sciences_weight + \
    save_pred.loc[student_index, 'NU_NOTA_LC'] * code_languages_weight + \
    save_pred.loc[student_index, 'NU_NOTA_CH'] * human_sciences_weight + \
    save_pred.loc[student_index, 'NU_NOTA_REDACAO'] * essay_weight) / total_weights
    
    # save in final grade list
    final_grades.append(current_grade)
# max value in weight average's students
max(final_grades)
data_file['MEDIA_PONDERADA'] = final_grades
data_file.keys()
weighted_average_dataframe = pd.DataFrame(data_file, columns= ['NU_INSCRICAO', 
        'NU_NOTA_CH','NU_NOTA_LC','NU_NOTA_CN','NU_NOTA_REDACAO', 
        'NU_NOTA_MT', 'MEDIA_PONDERADA']
)
weighted_average_dataframe.head()
sorted_dataframe = weighted_average_dataframe.sort_values(['MEDIA_PONDERADA'], ascending=False)
sorted_dataframe.head(20)
# get the 20 rows of better students and save column NU_INSCRICAO and NU_NOTA_MT
sorted_dataframe.iloc[0:, [0, -2]].to_csv('answer.csv', index=False, header=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13064058062480277, 'fraction_numerical': 0.004733354370463868, 'mean_word_length': 7.475935828877005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '375961', 'license': 'MIT', 'n_tokens_mistral': 1270, 'n_tokens_neox': 1226, 'n_words': 170, 'path': 'Challenge1/challenge1_enem.ipynb', 'repo_name': 'joberthrogers18/codenation-datascience', 'size': '3169'}