In [1]:
import numpy as np
from __future__ import print_function
In [2]:
x = np.arange(10)
print (x)
In [3]:
print(x * 2 + 1)
In [4]:
x = np.random.rand(10000000)
In [5]:
%%timeit
y = 2*x + 1
In [6]:
import pandas as pd
In [7]:
df = pd.DataFrame({'id' : ['A', 'B', 'A', 'b'], 'val' : [1, 2, 3, 4]})
print(df)
In [8]:
grouped = df.groupby('id').sum()
print(grouped)
In [9]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [10]:
x = np.linspace(0 ,10 ,1000)
plt.plot(x, np.sin(x))
Out[10]:
In [11]:
import numpy as np
import matplotlib.pyplot as plt
from scipy import special, optimize
x = np.linspace(0, 10, 1000)
opt = optimize.minimize(special.j1, x0=3)
plt.plot(x, special.j1(x))
plt.plot(opt.x, special.j1(opt.x), marker='o', color='red')
Out[11]:
In [14]:
x = 10*np.random.rand(100)
y = np.sin(x) + 0.1*np.random.rand(100)
plt.plot(x, y, '.k')
Out[14]:
In [16]:
from sklearn.ensemble import RandomForestRegressor
model = RandomForestRegressor()
model.fit(x[:, np.newaxis], y)
xfit = np.linspace(-1, 11, 1000)
yfit = model.predict(xfit[:, np.newaxis])
plt.plot(x, y, '.k')
plt.plot(xfit, yfit)
Out[16]:
In [ ]: