社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

yatu

yatu 最近创建的主题
yatu 最近回复了
6 年前
回复了 yatu 创建的主题 » Python networkx图形标签

问题是您没有指定任何 pos 节点的属性 Winterfell ,然后当您尝试访问它时 draw_networkx_edge_labels 它找不到它。

如果尝试给它一个position属性,请说:

      location    x    y
0      TheWall  145  570
1   Winterfell  142  520
2  WhiteHarbor  140  480

然后,可以正确访问所有节点的属性,并核心绘制网络:

plt.figure()
G=nx.Graph()

df1 = df1.reset_index(drop=True)
df2 = df2.reset_index(drop=True)

for i, x in enumerate(df1['location']):
    G.add_node(x, pos=(df1.loc[i,'x'], df1.loc[i,'y']))

for x, x2, w in zip(df2['location'], df2['x'], df2['y']):
    G.add_edge(x, x2, weight=w)

plt.figure(figsize=(15,15)) 

pos = nx.get_node_attributes(G, 'pos')
weights = nx.get_edge_attributes(G, 'weight') 
nx.draw(G, pos=pos, node_size=40, with_labels=True, fontsize=9)
nx.draw_networkx_edge_labels(G, pos=pos, edge_labels=weights)

plt.show()

enter image description here

你可以用 itertools.product 并设置一个 repeat 共3页:

from itertools import product
a, b = 10, 100
n = 3

list(product([a,b], repeat=n))

[(10, 10, 10),
 (10, 10, 100),
 (10, 100, 10),
 (10, 100, 100),
 (100, 10, 10),
 (100, 10, 100),
 (100, 100, 10),
 (100, 100, 100)]
6 年前
回复了 yatu 创建的主题 » 如何使用python创建非计数值的直方图?

看起来你想要的是条形图而不是直方图。注意a histogram 是:

数值资料分布的精确表示

它不同于条形图,因为条形图涉及两个变量,而直方图只涉及一个。 用于绘制条形图 matplotlib.pyplot.bar 以下内容:

X = [0,0,0,1,10,5,0,0,5]

import matplotlib.pyplot as plt 
plt.bar(range(len(X)), X)

enter image description here

6 年前
回复了 yatu 创建的主题 » python pandas数据帧整形

您可以重塑数据并创建新的数据帧:

cols = 6
rows = 4
df = pd.DataFrame(df.values.T.reshape(cols,rows).T)
df.rename(columns=df.iloc[0]).drop(0)

    A    B    C  A2 B2 C2
1  0.1  0.8  0.3  1  1  1
2  0.4  0.7  0.6  2  2  2
3  0.6  0.9  0.8  3  3  3
6 年前
回复了 yatu 创建的主题 » 在python中比较两个列表,只保留匹配项和不匹配项

你可能想用 集合 为此。 你可以找到有交集的公共元组( & )两组中:

match = set(data1) & set(data2)

你可以用对称差分或等价的方法得到非公共元素 ^ :

no_match = len(set(data1) ^ set(data2))

更多关于 sets — Unordered collections of unique elements 在连接的链接中。

一种方法是使用 scipy.ndimage.interpolation.zoom . 这将是 zooming 使用 spline interpolation . 为了使用它,您需要提供一个缩放因子,在这种情况下,假设您想要一个大小的数组 10 ,应该是 10/len(x) :

from scipy.ndimage import interpolation

x = np.array([10,50,40,20])
i = 10
z = i / len(x)
# 2.5

x_int = interpolation.zoom(x,z)

产量

array([10, 18, 35, 50, 54, 49, 40, 30, 23, 20])
6 年前
回复了 yatu 创建的主题 » 如何用机器学习算法设置多个班级?

您提到的这些算法都不局限于二进制分类问题。它们可以用于多分类问题,就像对二进制分类一样,通过调用 model.fit(x_train,y_train) .