<jupyter_start><jupyter_text>Relación Consumo de Internet con nº de tweets en CellID con datos meteorologicos<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from keras.layers import Dense
from keras.models import Sequential, Model
dataMeteoCellId = pd.read_csv('tres_semanas_mi_tweet_meteo.csv')
dataMeteoCellId.describe() 
dataMeteoCellId
dataMeteoCellId = dataMeteoCellId.drop (columns=['Unnamed: 0', 'Unnamed: 0.1', 'countrycode'])
x= []
y = []
for dataMeteoTweet in dataMeteoCellId.itertuples(index=False):
    x.append(np.array([dataMeteoTweet.temperature, dataMeteoTweet.precipitation]))
    y.append(dataMeteoTweet.tweet)
x = np.array(x)
y = np.array(y)
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.30,random_state=10)
model = Sequential()
model.add(Dense(100, input_dim = 2, activation = 'relu'))
model.add(Dense(1,activation='linear'))
model.summary()
model.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy'])
history1024 = model.fit(X_train, y_train, epochs=500, batch_size=1024, validation_data=(X_test, y_test), verbose = 1)
print ('\nhistory dict:', history1024.history)
Y_predKM = model.predict(X_test)
score = model.evaluate(X_test, y_test, verbose = 0)
print ('Keras model')
print (score[0])<jupyter_output><empty_output><jupyter_text>Relacion Consumo de Internet con nº de tweets en CellID<jupyter_code>#Get data from csv
dataSemanaCellId = pd.read_csv('semana_mi_tweet.csv', index_col = None)
# Delete useless Column
dataSemanaCellId = dataSemanaCellId.drop (columns=['Unnamed: 0'])
# Sort and create a new index
dataSemanaCellId = dataSemanaCellId.sort_values(by=['CellID', 'idx'])
dataSemanaCellId = dataSemanaCellId.reset_index(drop=True)
dataSemanaCellId.head(50)
dataSemanaCellId.head()
x= []
y = []
for i in range(dataSemanaCellId.shape[0]-2):
    print(i)
    if (dataSemanaCellId.loc[i]['CellID'] == dataSemanaCellId.loc[i+1]['CellID']):
        x.append(dataSemanaCellId.loc[i:(i+1)]['internet'].values)
        y.append(dataSemanaCellId.loc[i+1]['tweet'])
    else:
        print (dataSemanaCellId.loc[i]['CellID'], ' vs ', dataSemanaCellId.loc[i+1]['CellID'])
x = np.array(x)
y = np.array(y)
X_train, X_test, y_train, y_test = train_test_split(x, y, test_size=0.30,random_state=10)
model = Sequential()
model.add(Dense(100, input_dim = 2, activation = 'relu'))
model.add(Dense(1,activation='linear'))
model.summary()
model.compile(optimizer='adam', loss='mean_squared_error', metrics=['accuracy'])
model.fit(X_train, y_train, epochs=100, batch_size=64, validation_data=(X_test, y_test), verbose = 1)
history1024 = model.fit(X_train, y_train, epochs=500, batch_size=1024, validation_data=(X_test, y_test), verbose = 1)
Y_predKM = model.predict(X_test)
score = model.evaluate(X_test, y_test, verbose = 0)
print ('Keras model')
print (score[0])
history64 = model.fit(X_train, y_train, epochs=100, batch_size=64, validation_data=(X_test, y_test), verbose = 1)
#Need a big RAM memory, even making different opetations, the minus operation between matrix
np.mean(np.abs(model.predict(X_test) - y_test))
y_predKM = model.predict(X_test)<jupyter_output><empty_output><jupyter_text>Multiple linear model from SKlearn<jupyter_code>from sklearn.linear_model import LinearRegression
LModel = LinearRegression()
LModel.fit (X_train, y_train)
y_predLM = LModel.predict(X_test)
plt.figure (1)

plt.subplot(121)
plt.scatter(y_test, Y_predKM)
plt.xlabel('Actual values')
plt.ylabel('Predicted values')
plt.title('Keras Neural Network Model')
plt.subplot(122)
plt.scatter(y_test, y_predLM)
plt.xlabel('Actual values')
plt.ylabel('Predicted values')
plt.title('SKlearn Linear Regression Model')
from sklearn.metrics import mean_squared_error
mse = mean_squared_error(y_test, y_predLM)
print ('Linear Regression Model')
print (mse)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1363868986693961, 'fraction_numerical': 0.02175025588536336, 'mean_word_length': 7.497826086956522, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '475255', 'license': 'Apache-2.0', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1438, 'n_words': 288, 'path': 'tfm-milan/Deep_Learning_Twitter.ipynb', 'repo_name': 'mchamorros/DeepLearningMilan', 'size': '3908'}