It doesnt work, gives some errors.
I’m traying with this:
import dash
from dash import Input, Output, dcc, html, ctx
import plotly.express as px
from csv import reader
import pandas as pd
import numpy as np
from pandas import DataFrame
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
from sklearn.svm import SVR
df = pd.read_csv("pokerdata.csv")
tmp = df.select_dtypes(include=['Int64'])
df[tmp.columns]= tmp.astype('float64')
#df=df[1:].astype(dtype=np.float32, copy=True, errors='raise')
file_name = "pokerdata.csv"
with open(file_name, "r", encoding='cp437') as csv_file:
csv_reader = reader(csv_file)
head = next(csv_reader)
print("head:")
print(", ".join(head))
#print("Values:")
for row in csv_reader:
(", ".join(row))
app = dash.Dash(__name__)
df=df.copy()
chart9 = px.scatter_3d(data_frame=df,
x='VPIP',
y='PFR',
z='3Bet PF',
#color='!!!0 All-In Equity Adjusted BB/100',
#trendline="ols",
#trendline_color_override="red",
height=800,
width=800
)
graph9 = dcc.Graph(
id='graph9',
figure=chart9,
#className="five columns"
)
dropdown1_scatter3d_chart = dcc.Dropdown(
id="dropdown1_scatter3d_chart",
options=[{"value":label, "label":label} for label in df.columns],
value=df.columns[0],
clearable=False
)
dropdown2_scatter3d_chart = dcc.Dropdown(
id="dropdown2_scatter3d_chart",
options=[{"value":label, "label":label} for label in df.columns],
value=df.columns[0],
clearable = False
)
dropdown3_scatter3d_chart = dcc.Dropdown(
id="dropdown3_scatter3d_chart",
options=[{"value":label, "label":label} for label in df.columns],
value=df.columns[0],
clearable = False
)
scatter3_div = html.Div(children=[html.Div(children=[dropdown3_scatter3d_chart, dropdown1_scatter3d_chart,dropdown2_scatter3d_chart], className="row") , graph9], className="eight columns")
row6 = html.Div(children=[scatter3_div], className="eight columns")
layout = html.Div(children=[row6], style={"text-align": "center", "justifyContent":"center"})
app.layout = layout
@app.callback(
Output(graph9, "figure"),
Input(dropdown1_scatter3d_chart, "value"),Input(dropdown2_scatter3d_chart, "value"),Input(dropdown3_scatter3d_chart, "value")
)
def udpate_graph(drop1,drop2,drop3):
mesh_size = .02
margin = 0
dff = df[drop1]
X = dff[['VPIP', 'PFR']]
y = dff['3Bet PF']
# Condition the model on sepal width and length, predict the petal width
model = SVR(C=1.)
model.fit(X, y)
# Create a mesh grid on which we will run our model
x_min, x_max = X.min() - margin, X.max() + margin
y_min, y_max = X.min() - margin, X.max() + margin
xrange = np.arange(x_min, x_max, mesh_size)
yrange = np.arange(y_min, y_max, mesh_size)
xx, yy = np.meshgrid(xrange, yrange)
# Run model
pred = model.predict(np.c_[xx.ravel(), yy.ravel()])
pred = pred.reshape(xx.shape)
# Generate the plot
fig=graph9
fig = px.scatter_3d(dff, x=drop1, y=drop2, z=drop3)
fig.update_traces(marker=dict(size=5))
fig.add_traces(go.Surface(x=xrange, y=yrange, z=pred, name='pred_surface'))
#fig.show()
return fig
if __name__ == "__main__":
app.run_server(debug=True)
but there is an error with the ml
KeyError: "None of [Index(['VPIP', 'PFR'], dtype='object')] are in the [index]"
how can I solve this?