Skip to content

Commit 0f8d8ab

Browse files
committed
KM
1 parent 8ff8781 commit 0f8d8ab

5 files changed

Lines changed: 59 additions & 62 deletions

File tree

requeriments.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@ missingno==0.5.1
5555

5656
zipfile36==0.1.3
5757

58-
imblearn==0.0
58+
imblearn==0.0
59+
60+
wordcloud==1.7.0

toolkit/machine_learning.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,32 @@ def create_multiclass_prediction_df(model, class_names: List[str], X_test: Union
140140
if only_wrong:
141141
model_predictions_df = model_predictions_df[model_predictions_df['Top Prediction'] != model_predictions_df['Label']]
142142
# return the dataframe
143-
return model_predictions_df
143+
return model_predictions_df
144+
145+
def quickregression(name):
146+
from sklearn.metrics import mean_absolute_error, mean_squared_error, mean_absolute_percentage_error
147+
"""
148+
Function to save time when doing Machine Learning models.
149+
It only asks the name of the model to train and returns the scoring.
150+
151+
Parameters
152+
----------
153+
name = Name of the ML model.
154+
Input Example = LinearRegression
155+
156+
Returns
157+
----------
158+
MAE, MAPE, MSE, RMSE and R2 Scores.
159+
"""
160+
161+
# Fit of the model in the previously split X_train, y_train
162+
model = name()
163+
model.fit(X_train, y_train)
164+
# Predict of the model with X_test
165+
modpred = model.predict(X_test)
166+
# Scores of the model with y_test and the predict values.
167+
print("MAE test:", mean_absolute_error(y_test, modpred))
168+
print("MAPE test:", mean_absolute_percentage_error(y_test, modpred))
169+
print("MSE test:", mean_squared_error(y_test, modpred))
170+
print("RMSE test:", np.sqrt(mean_squared_error(y_test, modpred)))
171+
return(model.score(X_train, y_train))

toolkit/plot.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,30 @@ def sunburst(df, interior:str, exterior:str, col_num:str, title:str):
138138
fig = px.sunburst(df, path=[interior, exterior], values=col_num, template = 'plotly_dark')
139139
fig.update_layout(width=800, height=600, title = title)
140140
fig.show()
141+
142+
def wordcloudviz(column):
143+
import matplotlib.pyplot as plt
144+
from wordcloud import WordCloud
145+
"""
146+
Function to create a quick visualization of wordclouds in a given column of a dataframe called df.
147+
148+
Parameters
149+
----------
150+
column = name of the column of the dataframe.
151+
Input example: df['column_name']
152+
153+
Return
154+
---------
155+
A wordcloud visualization of the words in the column.
156+
"""
157+
# First, it concatenates the text in a "single" text.
158+
text = " ".join(comment for comment in column)
159+
160+
# Creates a wordcloud visualization
161+
wordcloud = WordCloud(width=800, height=800, background_color='white').generate(text)
162+
163+
plt.figure(figsize=(8, 8), facecolor=None)
164+
plt.imshow(wordcloud)
165+
plt.axis("off")
166+
plt.tight_layout(pad=0)
167+
plt.show()

toolkit/quickregression.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

toolkit/wordcloudviz.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)