Пример #1
0
def plot_feature_importances_cancer(model, cancer):
    n_features = cancer.data.shape[1]
    plt.barh(np.arange(n_features), model.feature_importances_, align='center')
    plt.yticks(np.arange(n_features), cancer.feature_names)
    plt.xlabel("Feature importance")
    plt.ylabel("Feature")
    plt.ylim(-1, n_features)
Пример #2
0
def check_sanity():
    fig = plt.figure(figsize=[10, 5])
    # Axes for flower image
    ax = fig.add_axes([.5, .4, .5, .5])

    # Displaay image
    result = process_image('flowers/test/1/image_06743.jpg')
    ax = imshow(result, ax)
    ax.axis('off')
    index = 77
    ax.set_title(cat_to_name[str(index)])

    # Prediction of image
    predictions, classes = predict('flowers/test/1/image_06743.jpg',
                                   model,
                                   device=device)

    # Create bar graph
    # Axis x and y
    ax1 = fig.add_axes([0, -.4, .888, .888])

    # Classes probability
    y_pos = np.arange(len(classes))

    # Horizontal bar chart to see it better
    plt.barh(y_pos, predictions, align='center', alpha=0.5)
    plt.yticks(y_pos, classes)
    plt.xlabel('probabilities')
    plt.show()
Пример #3
0
def plot_feature_importances_cancer(scores):
    names, val_scores = [name for name, _, _, _, _, _, _ in scores
                         ], [score for _, score, _, _, _, _, _ in scores]

    plt.rcParams["figure.figsize"] = [15, 9]
    n_features = len(names)
    plt.barh(range(n_features), val_scores, align='center')
    plt.yticks(np.arange(n_features), names)
    plt.xlabel("Accuracy")
    plt.ylabel("Model")
    path = WORKING_PATH + "/___comparison_cancer_model.png"
    plt.savefig(path)
    plt.clf()
    return path
Пример #4
0
def plotting_feature_importance(importance, model):
    """Plot the feature importances of the forest"""
    std = np.std([modelo.feature_importances_ for modelo in model.estimators_],
                 axis=0)
    index = np.argsort(feten)
    plt.figure(figsize=(15, 15))
    plt.title("Feature importances")
    plt.barh(range(X_train.values.shape[1]),
             feten[index],
             color="r",
             xerr=std[index],
             align="center")

    plt.yticks(range(X_train.values.shape[1]), index)
    plt.ylim([-1, X_train.values.shape[1]])
    return plt.show()
Пример #5
0
# TODO: Display an image along with the top 5 classes
model.eval()
class_names = []
# Process Image
image_path = 'input2.png'

# Give image to model to predict output
probs, classes, image = predict(image_path, model)
print('probs: {} and classes: {}'.format(probs, classes))

print(probs, classes)
print(cat_to_name)
print(model.class_to_idx)
#probs=probs.detach.numpy()
#classes=classes.detach.numpy()
print(probs, classes)
print(classes[0])
for i in classes[0]:
    class_names.append(model.class_to_idx.item(int(classes[0, i])))
print(class_names)
for c in classes:
    class_names.append(cat_to_name[c])
print('classnames: {}'.format(class_names))
# Show the image
ax = imshow(image)
plt.barh(probs, class_names)
plt.xlabel('Probability')
plt.title('Predicted Flower Names')
plt.show()
Пример #6
0
zz=yy.iloc[:,[5,6,7,8]]
d=zz[(zz.differ_day_standard!=0)|(zz.differ_day_source_copy2!=0)|(zz.differ_day_source!=0)|(zz.differ_day_standard_copy2!=0)]
standard=to_list(d["differ_day_standard"])
source=to_list(d["differ_day_source"])
source_copy2=to_list(d["differ_day_source_copy2"])
standard_copy2=to_list(d["differ_day_standard_copy2"])
zhaoyang=[0]*len(standard)
y=range(len(standard))


x1=sorted(standard)
x2=sorted(source)
x3=sorted(source_copy2)
x4=sorted(standard_copy2)



plt.barh(range(len(x1)), x1)
plt.barh(range(len(x2)), x2)
plt.barh(range(len(x3)), x3)
plt.barh(range(len(x4)), x4)



plt.show()





Пример #7
0
def main(argv):
    print("hello")

    # 读取表格
    data = xlrd.open_workbook("developers.xlsx")

    # 获取表格的sheets
    table = data.sheets()[0]

    # 输出行数量
    print(table.nrows)  # 8

    # 输出列数量
    print(table.ncols)  # 4

    # 获取第一行数据
    row1data = table.row_values(0)
    print(row1data)  # ['列1', '列2', '列3', '列4']
    print(row1data[0])  # 列1

    from pyecharts.charts import Bar

    # 读取表格
    # data = xlrd.open_workbook("developers.xlsx")

    # 获取表格的sheets
    table = data.sheets()[0]

    # 输出行数量
    print(table.nrows)

    # 输出列数量
    print(table.ncols)

    # 获取第一行数据
    row1data = table.row_values(0)
    print(row1data)  # ['列1', '列2', '列3', '列4']
    print(row1data[0])  # 列1

    xdata = []
    ydata = []
    for i in range(1, table.nrows):
        print(table.row_values(i))
        xdata.append(table.row_values(i)[0])
        ydata.append(table.row_values(i)[1])

    print(xdata)
    print(ydata)

    # 数据可视化,柱状图
    bar = Bar()
    bar.add_xaxis(xdata)
    bar.add_yaxis("名称1", ydata)
    bar.render("show.html")

    plt.bar(xdata, ydata)
    x = [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
    y = [5, 3, 6, 20, 17, 16, 19, 30, 32, 35]
    plt.plot(x, y)
    plt.show()

    a = np.random.randn(100)
    s = pd.Series(a)
    plt.hist(s)
    plt.show()

    x = ['Cat1', 'Cat2', 'Cat3', 'Cat4', 'Cat5']
    y = [5, 4, 8, 12, 7]
    plt.bar(x, y)
    plt.show()

    x = ['Cat1', 'Cat2', 'Cat3', 'Cat4', 'Cat5']
    y = [5, 4, 8, 12, 7]
    plt.barh(x, y)
    plt.show()

    nums = [25, 37, 33, 37, 6]
    labels = ['High-school', 'Bachelor', 'Master', 'Ph.d', 'Others']
    plt.pie(x=nums, labels=labels)
    plt.show()

    # 生成0-1之间的10*4维度数据
    data = np.random.normal(size=(10, 4))
    lables = ['A', 'B', 'C', 'D']
    # 用Matplotlib画箱线图
    plt.boxplot(data, labels=lables)
    plt.show()

    # flights = sns.load_dataset("flights")
    # data = flights.pivot('year', 'month', 'passengers')
    # sns.heatmap(data)
    # plt.show()

    N = 1000
    x = np.random.randn(N)
    y = np.random.randn(N)

    plt.scatter(x, y, marker='x')
    plt.show()

    N = 10000
    x = np.random.randn(N)
    y = np.random.randn(N)

    plt.scatter(x, y, marker='x')
    plt.show()

    labels = np.array([u"推进", "KDA", u"生存", u"团战", u"发育", u"输出"])
    stats = [83, 61, 95, 67, 76, 88]
    # 画图数据准备,角度、状态值
    angles = np.linspace(0, 2 * np.pi, len(labels), endpoint=False)
    stats = np.concatenate((stats, [stats[0]]))
    angles = np.concatenate((angles, [angles[0]]))
    # 用Matplotlib画蜘蛛图
    fig = plt.figure()
    ax = fig.add_subplot(111, polar=True)
    ax.plot(angles, stats, 'o-', linewidth=2)
    ax.fill(angles, stats, alpha=0.25)
    # 设置中文字体
    # font = FontProperties(fname=r"/System/Library/Fonts/PingFang.ttc", size=14)
    # ax.set_thetagrids(angles * 180/np.pi, labels, FontProperties=font)
    plt.show()

    # tips = sns.load_dataset("tips")
    # tips.head(10)
    # # 散点图
    # sns.jointplot(x="total_bill", y="tip", data=tips, kind='scatter')
    #
    # # Hexbin图
    # sns.jointplot(x="total_bill", y="tip", data=tips, kind='hex')
    # plt.show()

    df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])

    # 堆面积图
    df.plot.area()

    # 面积图
    df.plot.area(stacked=False)

    df = pd.DataFrame(np.random.randn(1000, 2), columns=['a', 'b'])
    df['b'] = df['b'] + np.arange(1000)

    # 关键字参数gridsize;它控制x方向上的六边形数量,默认为100,较大的gridsize意味着更多,更小的bin
    df.plot.hexbin(x='a', y='b', gridsize=25)

    print("end")
Пример #8
0
import matplotlib as plt
import seaborn as sns

sns.set()

config = configparser.ConfigParser()
config.read('willy.ini')
#
postgresql_pwd = config['POSTGRESQL'][
    'PASSWORD_POSTGRESQL']  # PostgreSQL password
#
# # Make connection tot PostgreSQL database
#
db_string = 'postgresql+psycopg2://postgres:' + postgresql_pwd + '@10.10.1.35/Willy'
# # Make connection to database with correct string
#
conn = create_engine(db_string)

teprinten = pd.read_sql_query('select * from navigation_geometry', con=conn)

fig = plt.figure()
plt.barh(teprinten['id'], teprinten['linear_x'], color='blue', align='center')
plt.title('Geometrie van navigatie', fontsize=16)
plt.xlabel('ID', fontsize=13)
plt.ylabel('Lineair X', fontsize=13)
plt.show()
naam = 'geometrie,jpg'
grid.fig.tight_layout(w_pad=1)
fig.savefig(naam)
plt.show()
Пример #9
0
plot([1,2,3,4,5,6]) #y轴点图
plot([4,3,2,1],[1,2,3,4]) #(y,x)轴的值
import matplotlib.pyplot as plt
x = [1,2,3,4] #some data
y = [5,4,3,2]

# create new figure
plt.figure()
plt.subplot(231) # plot折线图
plt.plot(x, y)

plt.subplot(232) # 柱状图
plt.bar(x, y)

plt.subplot(233) # 条状图
plt.barh(x, y)

plt.subplot(234) # stacked bar charts堆叠柱状图
plt.bar(x, y)

y1 = [7,8,5,3]  # more data for stacked bar charts
plt.bar(x, y1, bottom=y, color = 'r') # 底线[5,4,3,2] + 柱长[7,8,5,3]


plt.subplot(235) # 箱线图
plt.boxplot(x)

plt.subplot(236) # 散点图
plt.scatter(x,y)

dataset = [113,115,119,121,124,