def plot_in_2d(self, X, y, title=None):
     X_transformed = self.transform(X, y, n_components=2)
     x1 = X_transformed[:, 0]
     x2 = X_transformed[:, 1]
     plt.scatter(x1, x2, c=y)
     if titel: plt.titel(title)
     plt.show()
 def plot_in_2d(self, X, y, title=None):
     X_transformed = self.transform(X, y, n_components=2)
     x1 = X_transformed[:, 0]
     x2 = X_transformed[:, 1]
     plt.scatter(x1, x2, c=y)
     if titel: plt.titel(title)
     plt.show()
d = 10
number_of_selections = [0] * d
sum_of_rewards = [0] * d
ads_selected = []
total_reward = 0
for n in range(0, N):
    max_upper_bound = 0
    ad = 0
    for i in range(0, d):
        if (number_of_selections[i] > 0):
            average_rewards = sum_of_rewards[i] / number_of_selections[i]
            delta_i = math.sqrt(3 / 2 * math.log(n) / number_of_selections[i])
            upper_bound = average_rewards + delta_i
            print(upper_bound)
        else:
            upper_bound = 1e400

        if upper_bound > max_upper_bound:
            max_upper_bound = upper_bound
            ad = i
    ads_selected.append(ad)
    number_of_selections[ad] = number_of_selections[ad] + 1
    reward = data.values[n, ad]
    sum_of_rewards[ad] = sum_of_rewards[ad] + reward
    total_reward = total_reward + reward

plt.hist(ads_selected)
plt.titel('upper confidence bound')
plt.xlabel('advertaisments')
plt.ylabel('no. of times selected')
plt.show()
Esempio n. 4
0
# -*- coding: utf-8 -*-
"""
Created on Sat Feb  3 10:10:10 2018

@author: Administrator
"""
import pandas as pd
import matplotlib.pyplot as plt

train_path = r'C:\Users\Administrator\Desktop\AI_Camp\Tal_SenEvl_train_136KB.txt'
train_data = pd.read_table(train_path,names=["id","sent1","sent1","score"],header = None)

test_path = r'C:\Users\Administrator\Desktop\AI_Camp\Tal_SenEvl_test_62KB.txt'
test_data = pd.read_table(test_path,names=["id","sent1","sent1"],header = None)

#==============================================================================
# 载入train和test数据集
#==============================================================================
train_text = pd.DataFrame()
train_text['sentence1'] = [preProcess(x) for x in list(train_data['sent1'])]
train_text['sentence2'] = [preProcess(x) for x in list(train_data['sent1'])]

test_text = pd.DataFrame()
test_text['sentence1'] = [preProcess(x) for x in list(test_data['sent1'])]
test_text['sentence2'] = [preProcess(x) for x in list(test_data['sent1'])]

plt.figure(figsize=(20,10)) 
train_data.score.value_counts().plot(kind="bar")
plt.titel('Scores distribution')
plt.show()
"""

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

dataset = pd.read_csv('Position_Salaries.csv')
x = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values

# create regressor here

y_pred = regressor.predict(6.5)

plt.scatter(x, y, color='blue')
plt.plot(x, regressor.predict(x), color='red')
plt.titel('Truth vs bluff')
plt.xlabel('position level')
plt.ylabel('Salary')
plt.show()

# fro hd
x_grid = np.arrange(min(x), max(x), 0.1)
x_grid = x_grid.reshape((len(x_grid, 1)))
plt.scatter(x, y, color='blue')
plt.plot(x_grid, regressor.predict(x_grid), color='red')
plt.titel('Truth vs bluff')
plt.xlabel('position level')
plt.ylabel('Salary')
plt.show()
#compute optimal strategy
alpha_t_MKV = opt_control(X_t, control_coef_MKV['eta'],
                          control_coef_MKV['chi'], -b2 / rt)

# simulated running cost
f_t = .5 * (qt * X_t**2 + bar_qt *
            (X_t - st * bar_mu_t_MKV)**2 + rt * alpha_t_MKV**2)
# terminal cost
g_T = .5 * (qT * X_t[:, -1]**2 + bar_qT *
            (X_t[:, -1] - sT * bar_mu_t_MKV[-1])**2)
# sample value function in w.r.t. time
temp = np.insert(np.cumsum(f_t[:, :-1], axis=1), 0, 0, axis=1)
sample_v_t = (temp[:, -1].reshape(N_simulate, 1) -
              temp) * t_step + g_T.reshape(N_simulate, 1)

v_t_sim_MKV = np.sum(sample_v_t / N_simulate, axis=0)

#%% test dynamic process X_t
plt.figure()
plt.plot(np.sum(X_t / N_simulate, axis=0), color='blue')
plt.plot(bar_mu_t_MKV, color='red')
plt.title('bar_mu & sim_Xt_mu')

plt.figure()
plt.plot(t, v_t_sim_MKV)
plt.titel('v_t_sim_MKV')
#plt.axhline(y=v_0,xmin=0,xmax=1,c="blue",linewidth=0.5,zorder=0)

print('value function by simulation: {:.10f}'.format(v_t_sim_MKV[0]))
#print('value function by formula: {:.10f}'.format(v_0))
Esempio n. 7
0
 def plot_bar(self):
     plt.hist(self.data)
     plt.xlabel('Results')
     plt.ylabel('Frequency')
     plt.titel('Binomial Distribution')
     plt.show()
Esempio n. 8
0
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

dataset = pd.read_csv('Position_Salaries.csv')
x = dataset.iloc[:, 1:2].values
y = dataset.iloc[:, 2].values

from sklearn.preprocessing import StandardScaler

sc_x = StandardScaler()
sc_y = StandardScaler()
x = sc_x.fit_transform(x)
y = sc_y.fit_transform(y)

# create regressor here
from sklearn.svm import SVR

regressor = SVR(kernel='rbf')
regressor.fit(x, y)

y_pred = sc_y.inverse_transform(
    regressor.predict(sc_x.transform(np.array([[6.5]]))))

plt.scatter(x, y, color='blue')
plt.plot(x, regressor.predict(x), color='red')
plt.titel('Truth vs bluff (SVR)')
plt.xlabel('position level')
plt.ylabel('Salary')
plt.show()