<jupyter_start><jupyter_text>Procedo a tratar y escalar los datos para aplicar modelo<jupyter_code>from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error, r2_score
import seaborn as sns
import os
scaler = StandardScaler()
df_distrias_grouped.head()
Y = df_distrias_grouped['CANTIDAD']
Y = Y.drop(index=Y.index[0], 
        axis=0)
standard_df = scaler.fit_transform(df_distrias_grouped)
standard_df = pd.DataFrame(standard_df,columns = list(df_distrias_grouped.columns))
#X = df_distrias_grouped#['VALOR_TOTAL']
#X = pd.factorize(standard_df['COSTO'])[0].reshape(-1, 1) 
X = standard_df#df_distrias_grouped['VALOR_DESCUENTO']
#sns.boxplot(x=df_distrias_grouped['VALOR_UNITARIO'])
X.drop(['CANTIDAD'], axis = 1, 
        inplace=True)
X.drop(index=X.index[-1], 
        axis=0, 
        inplace=True)
#X = pd.factorize(X)[0].reshape(-1, 1) 
#sns.boxplot(x=df_distrias_grouped['PRODUCTO_SERVICIO'])
#sns.boxplot(x=df_distrias_grouped['TOTAL_NETO'])
sns.boxplot(x=df_distrias_grouped['CANTIDAD'])
sns.boxplot(x=df_distrias_grouped['RENTABILIDAD'])
plt.figure(figsize=(15,10))
plt.plot(X,Y,"b.")#plt.plot(X,Y, "b.")
plt.xlabel("$X$", fontsize=18)
plt.ylabel("$Y$", rotation=0, fontsize=18)
plt.show()<jupyter_output><empty_output><jupyter_text>Aplico Regresion Lineal y Ridge<jupyter_code>lin_reg = LinearRegression()
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.222)#, random_state=42
lin_reg.fit(X_train, y_train)
#lin_reg.intercept_, lin_reg.coef_
from sklearn.metrics import mean_absolute_error
# Make predictions using the testing set
Y_pred = lin_reg.predict(X_test)
# Realizo predicion con los otros dataframe de pruebas.
Y_pred2 = lin_reg.predict(X_train)

# The coefficients
print("Coefficients: \n", lin_reg.coef_)
#The mean squared error test
#print(f"Mean squared error of test: {mean_squared_error(y_test, Y_pred)}")
print(f"Mean absolute error of test: {mean_absolute_error(y_test, Y_pred)}")
# The mean squared error train
print(f"Mean squared error of Train: {mean_squared_error(y_train, Y_pred2)}")
#print("Mean squared error: %.2f" % mean_squared_error(y_test, Y_pred))
# The coefficient of determination: 1 is perfect prediction
print(f"Coefficient of determination: {r2_score(y_test, Y_pred)}")
plt.hist(y_test)
plt.hist(Y_pred)<jupyter_output><empty_output><jupyter_text>Grafico los valores<jupyter_code># Plot outputs
X_test_sample = pd.factorize(X_test['COSTO'])[0].reshape(-1, 1)
plt.scatter(X_test_sample, y_test, color="black")
plt.plot(X_test_sample, y_test, color="blue", linewidth=3)
from sklearn.linear_model import Ridge
#n_samples, n_features = Y.count(),X.shape[1]
#g = np.random.RandomState(0)
# = rng.randn(n_samples)
# = rng.randn(n_samples, n_features)
clf = Ridge(alpha=1.0)
clf.fit(X_train, y_train)#fit(X, y)

# Make predictions using the testing set
Y_pred = clf.predict(X_test)
# Realizo predicion con los otros dataframe de pruebas.
#Y_pred2 = clf.predict(X_train)

# The coefficients
print("Coefficients: \n", clf.coef_)
print(f"Mean squared error of test: {mean_absolute_error(y_test, Y_pred)}")<jupyter_output>Coefficients: 
 [  -2699.46743141   13055.90545329   11504.32414495   55512.06371504
  -12902.04919475   -5602.12735495     325.80039208    7619.50725327
 -124547.65851337   12013.35616021    8798.77103933   70572.03917372
    7973.33110856   -2760.98119555  -57091.72859319]
Mean squared error of test: 84196.84381356873<jupyter_text>Pocos datos.Se toma en general en estadistica de todos los productos de la empresa.Comportamientos ciclicos o estacionales.Resumen de las variables.Top de 5 de los productos.Recomendacion.Con este modelo se podria estimar las cantidades estimadas que se podria con este mismo.<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1217750257997936, 'fraction_numerical': 0.06346749226006192, 'mean_word_length': 6.800804828973843, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '359036', 'license': 'MIT', 'n_tokens_mistral': 1674, 'n_tokens_neox': 1497, 'n_words': 292, 'path': 'DistriasNotebook.ipynb', 'repo_name': 'negly/ds-notebooks', 'size': '3876'}