import pandas as pd import matplotlib.pyplot as plt import seaborn as sns import numpy as np datafile = open("all_data.txt", "r").readlines() all_data = np.zeros((4, len(datafile))) for i, line in enumerate(datafile): total = line.split(" ") all_data[:, i] = total df = pd.DataFrame(data=all_data) sns.plot(data=df)
ax.set_xlabel('something', fontsize=16) ax.set_title('I am title', fontsize=20) ax.set_xlim([0.,50.]) ax.set_ylim([0, 100]) plt.show() #<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> ## Lineplot # Seaborn ax = sns.pointplot(x=x, y=y, hue='gender',data=df, marker=['o','x'], linestyle=['-','--'], join=True, color='#bb3f3f', order=['Dinner','Lunch'], estimator=np.median, capsize=.2) # Matplotlib ax = sns.plot(x,y) ax.set_ylabel('y', fontsize=16) ax.set_xlabel('x', fontsize=16) ax.set_title('title', fontsize=20) ax.set_xlim([0.,50.]) ax.set_ylim([0, 100]) plt.show() #<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> ## Heatmap (Correlate) # Seaborn mean_corr = bcw_mean[[x for x in bcw_mean.columns if x not in 'id']].corr()
# coding=utf-8 import seaborn as sns import matplotlib as mt import pandas as pd import numpy as np import sys if __name__ == "__main__": # 一维线性回归数据 data1 = pd.read_csv('resources/data1.txt', header=None, names=['x', 'y']) print(data1) # 二维线性回归数据 data2 = pd.read_csv('resources/data2.txt', header=None, names=['x', 'y', 'z']) print(data2) sns.jointplot(x='x', y='y', data=data1) sns.jointplot(x='x', y='y', data=data2) sns.plot([1, 2, 3, 4]) sns.plt.show() def plot(data, x_name='x', y_name='y'): sns.jointplot(x=x_name, y=y_name, data=data) sns.plt.show()
def main(): # Initialisieren aller Pygame-Module und # Fenster erstellen (wir bekommen eine Surface, die den Bildschirm repräsentiert). pygame.init() agent = DQNAgent() counter_games = 0 record = 0 while counter_games < 150: screen = pygame.display.set_mode((800, 600)) # Titel des Fensters setzen, Mauszeiger nicht verstecken und Tastendrücke wiederholt senden. pygame.display.set_caption("Pygame-Tutorial: Animation") pygame.mouse.set_visible(1) pygame.key.set_repeat(1, 30) pygame.font.init() # you have to call this at the start, myfont = pygame.font.SysFont('Comic Sans MS', 30) # Clock-Objekt erstellen, das wir benötigen, um die Framerate zu begrenzen. clock = pygame.time.Clock() # Wir erstellen eine Tilemap. map = Tilemap.Tilemap() event = AutoInput.AutoInput() # Die Schleife, und damit unser Spiel, läuft solange running == True. running = True max_steps_reached = False max_steps = 100 step = 0 max_score = map.player.pos_x max_score_evolution = [] while running and not max_steps_reached: agent.epsilon = 80 - counter_games #get old state state_old = agent.get_state(map) map.player.pos_x_old = map.player.pos_x #perform random actions based on agent.epsilon, or choose the action if randint(0, 200) < agent.epsilon: final_move = to_categorical(randint(0, 2), num_classes=3) else: # predict action based on the old state prediction = agent.model.predict(state_old.reshape((1, 7))) final_move = to_categorical(np.argmax(prediction[0]), num_classes=3) # Framerate auf 30 Frames pro Sekunde beschränken. # Pygame wartet, falls das Programm schneller läuft. clock.tick(30) # screen Surface mit Schwarz (RGB = 0, 0, 0) füllen. screen.fill((198, 209, 255)) map.handle_input(final_move) #continue jump animation after if map.player.isjump: map.player.jump() # Die Tilemap auf die screen-Surface rendern. map.render(screen) textsurface = myfont.render( "Game " + str(counter_games) + " Step " + str(step) + " Max Score " + str(max_score), False, (0, 0, 0)) screen.blit(textsurface, (50, 50)) #Print Hindernis onto map and check if there should be a new one if not map.isThereHindernis: map.createNewHindernis() map.isThereHindernis = True map.hindernis.move() map.hindernis.render(screen) map.checkHindernisOnMap() state_new = agent.get_state(map) crash = map.collisionDetection() #set treward for the new state reward = agent.set_reward(map.player, crash) #train short memory base on the new action and state agent.train_short_memory(state_old, final_move, reward, state_new, running) # Inhalt von screen anzeigen pygame.display.flip() if map.player.pos_x > max_score: max_score = map.player.pos_x step += 1 if step >= max_steps: max_steps_reached = True max_score_evolution.append(max_score) agent.remember(state_old, final_move, reward, state_new, running) #record = get_record(map.player.pos_x, record) #if display_option: # #display(player1, food1, game, record) # pygame.time.wait(speed) agent.replay_new(agent.memory) counter_games += 1 agent.model.save_weights('weights.hdf5') sns.plot(max_score_evolution)
# ##### The segmentation with 4 clusters looks good as it has segmented the high frequent and high monetary customer with less recency time # In[540]: retail_RFM_melt = pd.melt(retail_RFM_k4.reset_index(), id_vars=['CustomerID', 'Cluster'], value_vars=['Recency', 'Frequency', 'MonetaryValue'], var_name='Attribute', value_name='Value') retail_RFM_melt = pd.DataFrame(retail_RFM_melt) # In[ ]: plt.title('Snake Plot for standardized variables') sns.plot(x="Attribute", y="Value", hue='Cluster', data=retail_RFM_melt) # In[542]: cluster_avg = retail_RFM_k4.groupby(['Cluster']).mean() population_avg = retail_RFM.mean() relative_imp = cluster_avg / population_avg - 1 # In[543]: #Relative distance from each parameter plt.figure(figsize=(10, 2)) sns.heatmap(relative_imp, annot=True, cmap='RdYlGn') # ### 4. Conclusion
# In[31]: df.set_index('line').grouby(plot() # In[30]: df.plot(x='sample', y='number_of_rhizoids', subplots=True) # In[25]: import seaborn as sns sns.plot(df) # In[8]: from numpy.random import choice # In[9]: get_ipython().magic('pinfo choice') # In[4]: ### Using an index, which is what I would do.
ax.set_xlabel('something', fontsize=16) ax.set_title('I am title', fontsize=20) ax.set_xlim([0.,50.]) ax.set_ylim([0, 100]) plt.show() #<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> ## Lineplot # Seaborn ax = sns.pointplot(x=x, y=y, hue='gender',data=df, marker=['o','x'], linestyle=['-','--'], join=True, color='#bb3f3f', order=['Dinner','Lunch'], estimator=np.median, capsize=.2) # Matplotlib ax = sns.plot(x,y) ax.set_ylabel('y', fontsize=16) ax.set_xlabel('x', fontsize=16) ax.set_title('title', fontsize=20) ax.set_xlim([0.,50.]) ax.set_ylim([0, 100]) plt.show() #<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> ## Heatmap (Correlate) # Seaborn corr = df.corr ax = sns.heatmap(corr, vmin=0, vmin=1, annot=False, square=True, linewidths=.5, cmap="YlGnBu", cbar=True)
# In[3]: path = '../../resources/SimpleRegressionDataSet/simple_regression.csv' # In[4]: data_1 = pd.read_csv(path, header=None) # In[5]: data_1.head(n=10) # In[12]: data_1.columns = ['population', 'profit'] data_1.head(n=2) # In[ ]: import seaborn as sns sns.set(color_codes=True) tips = sns.load_dataset("tips") plot = sns.lmplot(x="population", y="profit", data=data_1) # In[ ]: plot = sns.plot(x="population", y="profit", data=data_1) # In[ ]:
from sklearn.model_selection import train_test_split from sklearn.neighbors import KNeighborsClassifier from sklearn.metrics import classification_report, confusion_matrix ''' PROJECT TO DETERMINE BEST VALUE FOR KNN -given artificial dataset -code can be used for parameter tuning ''' df = pd.read_csv('KNN_Project_Data') df.head() sns.pairplot(df, hue='TARGET CLASS', palette='coolwarm') sns.plot() scaler = StandardScaler() scaler.fit(df.drop('TARGET CLASS', axis=1)) scaled_features = scaler.transform(df.drop('TARGET CLASS', axis=1)) df_feat = pd.DataFrame(scaled_features, columns=df.columns[:-1]) df_feat.head() X_train, X_test, y_train, y_test = train_test_split(scaled_features, df['TARGET CLASS'], test_size=0.30) knn = KNeighborsClassifier(n_neighbors=1) knn.fit(X_train, y_train)
orient='v') OARGBvCHM.set(xlabel='Feature groups', ylabel='UA (%)') loc, labels = plt.xticks() sns.despine() OARGBvCHMFig = OARGBvCHM.get_figure() OARGBvCHMFig.savefig( r"C:\Users\Study\OneDrive - University of the Sunshine Coast\Documents\Thesis\Manuscript\Figures\Table5_ModelPerf\UA-Pine-RGBvCHM-Delta.pdf", bbox_inches='tight', dpi=300) # %% plt.figure(figsize=(13, 6)) sns.set_theme(style="ticks") OARGBvCHM = sns.plot(accValues['UA-Lan round'], palette='colorblind', order=['RGB', 'TEX', 'RGB-TEX'], capsize=0.025, orient='v') OARGBvCHM.set(xlabel='Feature groups', ylabel='UA (%)') loc, labels = plt.xticks() sns.despine() OARGBvCHMFig = OARGBvCHM.get_figure() OARGBvCHMFig.savefig( r"C:\Users\Study\OneDrive - University of the Sunshine Coast\Documents\Thesis\Manuscript\Figures\Table5_ModelPerf\UA-Pine-RGBvTEX-Delta.pdf", bbox_inches='tight', dpi=300) # %% g = sns.FacetGrid(accValues, col=['Lantana', 'Slash pine'], col_wrap=2,
data_df = df[['GeoID', 'Date'] + sir_cols] us_data = data_df[data_df["GeoID"] == "United States__nan"] # In[ ]: # In[2]: sns.plot(us_data["Date"], us_data["Infected"]) # In[ ]: odeint() # In[10]: # routine to forecast the next X days given an SIR model and params def forecast_future(S, I, R, beta, gamma, days): y_i = S, I, R
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Jan 24 10:26:22 2018 @author: peternagy96 """ import pickle from matplotlib import pyplot as plt import seaborn as sb results = pickle.load(open('final_results_0.332.p', 'rb')) plt.figure() sb.set_style('darkgrid') pred_hist = sb.load_dataset(results['pred_hist']) sb.plot(pred_hist) plt.show()