大佬教程收集整理的这篇文章主要介绍了熊猫数据框中的无序和重复索引,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
x test X Train y Train 我们目前正在做一个室内定位系统项目。我们目前正在使用 KNN 来预测位置。 编写的代码如下
# Function to return the List of distances of the test records from Train records
def distNeighbours(X_Train,Y_Train,X_test,K):
distance=[]
for i in range(len(X_Train)):
edistance=0
for j in range(len(X_Train.columns)):
edistance+=round(np.sqrt(pow((X_Train.iloc[i,j]-X_test[j]),2)),2)
distance.append((edistance,i,Y_Train.iloc[i]))
distance=sorted(distance,key=lambda x: x[0])[0:K]
return distance
def preDictOutputNumeric(X_Train,K):
neighbours=[]
responses=[]
for i in range(len(X_test)):
neighbours.append(distNeighbours(X_Train,X_test.iloc[i,:],K))
for i in neighbours:
mean=0
for j in i:
mean+=j[-1]
mean=mean/K
responses.append(mean)
return responses
当测试数据被双重标记时,我们得到一个输出作为熊猫系列的列表,当转换为数据帧时,我们得到的索引值是无序的,有些是重复的。由于索引混乱,我们仍然不知道代码的哪一部分有错误。 Output which we are getTing Sample data which we are using
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的熊猫数据框中的无序和重复索引全部内容,希望文章能够帮你解决熊猫数据框中的无序和重复索引所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。