我想模拟一个磁盘满的情况。这样,当一定数量的文件上传到一个位置后,它会自动切换到不同的路径。
@application.route("/uploader" , methods=['GET', 'POST'])
def uploader():
count = 0
if (count < 3):
if request.method=='POST':
f = request.files['file1']
f.save(os.path.join(application.config['UPLOAD_FOLDER1'], secure_filename(f.filename)))
count = count + 1
return "Uploaded successfully!"
else:
if request.method=='POST':
f = request.files['file2']
f.save(os.path.join(application.config['UPLOAD_FOLDER2'], secure_filename(f.filename)))
return "Uploaded successfully!"
但是它拒绝转到其他提供的位置。
# Create empty lists
S=[] # this is to store Silhouette scores
comb=[] # this is to store combinations of epsilon / min_samples
# Define ranges to explore
eps_range=range(6,12) # note, we will scale this down by 100 as we want to explore 0.06 - 0.11 range
minpts_range=range(3,8)
for k in eps_range:
for j in minpts_range:
# Set the model and its parameters
model = DBSCAN(eps=k/100, min_samples=j)
# Fit the model
clm = model.fit(X_scaled)
# Calculate Silhoutte Score and append to a list
S.append(metrics.silhouette_score(X_scaled, clm.labels_, metric='euclidean'))
comb.append(str(k)+"|"+str(j)) # axis values for the graph
# Plot the resulting Silhouette scores on a graph
plt.figure(figsize=(16,8), dpi=300)
plt.plot(comb, S, 'bo-', color='black')
plt.xlabel('Epsilon/100 | MinPts')
plt.ylabel('Silhouette Score')
plt.title('Silhouette Score based on different combnation of Hyperparameters')
plt.show()
model83 = DBSCAN(eps=0.08, # default=0.5, The maximum distance between two samples for one to be considered as in the neighborhood of the other.
min_samples=3, # default=5, The number of samples (or total weight) in a neighborhood for a point to be considered as a core point.
metric='euclidean', # default='euclidean'. The metric to use when calculating distance between instances in a feature array.
metric_params=None, # default=None, Additional keyword arguments for the metric function.
algorithm='auto', # {‘auto’, ‘ball_tree’, ‘kd_tree’, ‘brute’}, default=’auto’, The algorithm to be used by the NearestNeighbors module to compute pointwise distances and find nearest neighbors.
leaf_size=30, # default=30, Leaf size passed to BallTree or cKDTree.
p=None, # default=None, The power of the Minkowski metric to be used to calculate distance between points. If None, then p=2
n_jobs=None, # default=None, The number of parallel jobs to run. None means 1 unless in a joblib.parallel_backend context. -1 means using all processors.
)
# Second model: eps=0.06, MinPts=6
model66 = DBSCAN(eps=0.06, min_samples=6) # note, as above this uses default value for other parameters
# Fit the models
clm83 = model83.fit(X_scaled)
clm66 = model66.fit(X_scaled)
df['DBSCAN Clusters 83']=clm83.labels_
df['DBSCAN Clusters 66']=clm66.labels_
df
# Sort the dataframe so clusters in the legend follow the number order
df=df.sort_values(by=['DBSCAN Clusters 83'])
# Create a 3D scatter plot
fig = px.scatter_3d(df, x=df['X3 distance to the nearest MRT station'], y=df['X2 house age'], z=df['Y house price of unit area'],
opacity=1, color=df['DBSCAN Clusters 83'].astype(str),
color_discrete_sequence=['black']+px.colors.qualitative.Plotly,
hover_data=['X5 latitude', 'X6 longitude'],
width=900, height=900
)
# Update chart looks
fig.update_layout(#title_text="Scatter 3D Plot",
showlegend=True,
legend=dict(orientation="h", yanchor="bottom", y=0.04, xanchor="left", x=0.1),
scene_camera=dict(up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=-0.2),
eye=dict(x=1.5, y=1.5, z=0.5)),
margin=dict(l=0, r=0, b=0, t=0),
scene = dict(xaxis=dict(backgroundcolor='white',
color='black',
gridcolor='#f0f0f0',
title_font=dict(size=10),
tickfont=dict(size=10),
),
yaxis=dict(backgroundcolor='white',
color='black',
gridcolor='#f0f0f0',
title_font=dict(size=10),
tickfont=dict(size=10),
),
zaxis=dict(backgroundcolor='lightgrey',
color='black',
gridcolor='#f0f0f0',
title_font=dict(size=10),
tickfont=dict(size=10),
)))
# Update marker size
fig.update_traces(marker=dict(size=2))
fig.show()