Current plot and anticipated plot
我是python的新手。我正在尝试从https://github.com/ageron/handson-ml/blob/master/02_end_to_end_machine_learning_project.ipynb
获取住房指数数据集的子集我已将数据集导入为“住房”。我正在尝试在显示所有中位数_p_value的图的上方仅画出第0.95分位数的离群值
import matplotlib.image as mpimg
housing.plot(kind="scatter", x="median_income", y="median_house_value",
alpha=0.1)
这将得到所有行(i)的图,我正尝试为0.95分位数的mid_house_value的子集选择相应的medium_income行,并将它们绘制在顶部的橙色(j)中
到目前为止,这是我迄今为止的最佳尝试,
plt.plot(housing.groupby('median_house_value').quantile(q=quant)["median_income"], housing.groupby('median_house_value').quantile(q=quant).index.get_level_values('median_house_value'),"or")
通过这样做,我可以获得分位数中的位数_房屋_值行。
quantile = int(round(housing["median_house_value"].quantile(q=0.95)))
housing.median_house_value > quantile
我想最后得到两个熊猫数组,一个用于x轴,一个与第二个数组相对应的中值_收入行数组,第二个数组将是构成分位数的中值_房子_值行数组
谢谢。
答案 0 :(得分:1)
IIUC-由于具有布尔索引# REQUIRED THRESHOLD
quantile = int(round(housing["median_house_value"].quantile(q=0.95)))
# FILTER BY BOOLEAN
upper_housing = housing[housing["median_house_value"] > quantile]
# PLOTTING
housing.plot(kind="scatter", x="median_income", y="median_house_value", alpha=0.1, c='blue')
upper_housing.plot(kind="scatter", x="median_income", y="median_house_value", alpha=0.1, c='red')
plt.show()
,因此只需过滤主数据集即可。
// SAME VALUES FROM THE FIRST ANSWER BUT WITH ANOTHER UPLOAD SYSTEM
if(Input::hasFile('imagen')) {
$time = Carbon::now()->format('Y-m-d');
$image = $request->file('imagen');
$extension = $image->getClientOriginalExtension();
$name = $image->getClientOriginalName();
$fileName = $time."-".$name;
// UPLOAD AND RUN YOUR SQL CODE IF YOU WANT ...
$path = \Storage::putFile('your_path', $image);
# LARAVEL WILL GENRATE A UNIQUE FILE NAME ;)
return dd($path);
// OR RETURN JSON RESPONSE IF YOU USE AJAX ;)
return response()->json([
'title' => $fileName,
'path' => $path,
'status' => 'success'
]);
}