<commit_before>#!/bin/python

from sklearn.linear_model import RidgeCV
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.dates import date2num
from datetime import datetime

def datestr2num(s):
    return date2num(datetime.strptime(s, '%Y-%m-%d'))

data = np.loadtxt(fname = 'weather.txt', delimiter = ',', converters = {0: datestr2num})
X, y = data[:,1:4], data[:,4]

print X
print y

m = X.shape[0] #number of samples

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

clf = RidgeCV(alphas = [0.1, 1.0, 10.0], normalize=True)
clf.fit(X_train, y_train)

prediction = clf.predict(X_test);
print 'X_test is: %f'
print X_test
print 'Expected is: %f' % y_test[0]
print 'Prediction is: %f' % prediction[0]
print "Score: %f" % clf.score(X, y)
print "Alpha: %f" % clf.alpha_

plt.figure(1)
real, = plt.plot(np.arange(m), y, 'b-', label='real')
predicted, = plt.plot(np.arange(m), clf.predict(X), 'r-', label='predicted')
plt.ylabel('Temperature')
plt.xlabel('Date')

plt.legend([real, predicted], ['Real', 'Predicted'])

plt.show()

#predict the number of the user input
t = input('Today\'s temperature:')
h = input('Today\'s humidity:')
w = input('Today\'s wind speed:')
user_input = np.array([t, h, w]).reshape(1, -1)
print "Tomorrow's temperature: %f" % clf.predict(user_input)<commit_msg>X axis shows the dates and 0ºC line is shown<commit_after>#!/bin/python

from sklearn.linear_model import RidgeCV
from sklearn.model_selection import train_test_split
import numpy as np
import matplotlib.pyplot as plt
#from matplotlib.dates import date2num
import matplotlib.dates as mdates
from datetime import datetime

def datestr2num(s):
    return date2num(datetime.strptime(s, '%Y-%m-%d'))

data = np.loadtxt(fname = 'weather.txt', delimiter = ',', converters = {0: mdates.strpdate2num('%Y-%m-%d')})
print data
X0, X, y = data[:,0], data[:,0:4], data[:,4]

print X
print y

m = X.shape[0] #number of samples

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

clf = RidgeCV(alphas = [0.1, 1.0, 10.0], normalize=True)
clf.fit(X_train, y_train)

prediction = clf.predict(X_test);

print 'X_test is: %f'
print X_test
print 'Expected is: %f' % y_test[0]
print 'Prediction is: %f' % prediction[0]
print "Score: %f" % clf.score(X, y)
print "Alpha: %f" % clf.alpha_

#plotting
plt.figure(1)
real, = plt.plot(X0, y, 'b-', label='real')
predicted, = plt.plot(X0, clf.predict(X), 'r-', label='predicted')

#gca = get current axis
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d/%m/%Y'))
plt.gca().xaxis.set_major_locator(mdates.MonthLocator())
plt.axhline(y=0, color='g')
#gcf = get current figure
plt.gcf().autofmt_xdate()

#legend
plt.ylabel('Temperature')
plt.xlabel('Date')
plt.legend([real, predicted], ['Real', 'Predicted'])

plt.show()

#predict the number of the user input
t = input('Today\'s temperature:')
h = input('Today\'s humidity:')
w = input('Today\'s wind speed:')
user_input = np.array([t, h, w]).reshape(1, -1)
print "Tomorrow's temperature: %f" % clf.predict(user_input)
{'fraction_non_alphanumeric': 0.17434740573638413, 'fraction_numerical': 0.01675797615211086, 'mean_word_length': 5.493723849372385, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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}}
{'dir': 'git-commits-cleaned', 'id': '3840817', 'n_tokens_mistral': 1251, 'n_tokens_neox': 1222, 'n_words': 305}