Python中关于SVM物种分布模型代码报错
最近看了这篇文章:https://blog.csdn.net/wong2016/article/details/83151122
里面用sklearn的数据集结合SVM画了物种分布图,遂想要试试看,手头有字典形式的TXT数据集,但并不是特别会写,遂参考链接文中的代码进行修改和复制(非商用)。
想发个帖子求助一下……哪位前辈给康康哪里错了……脑阔痛=。=
**from __future__ import print_function
from time import time
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets.base import Bunch
#from sklearn.datasets import fetch_species_distributions
from sklearn.datasets.species_distributions import construct_grids
from sklearn import svm, metrics
# if basemap is available, we'll use it.
# otherwise, we'll improvise later...
try:
from mpl_toolkits.basemap import Basemap
basemap = True
except ImportError:
basemap = False
print(__doc__)
def create_species_bunch(species_name, train, test, coverages, xgrid, ygrid):
"""Create a bunch with information about a particular organism
This will use the test/train record arrays to extract the
data specific to the given species name.
"""
bunch = Bunch(name=' '.join(species_name.split("_")[:2]))
species_name = species_name.encode('ascii')
points = dict(test=test, train=train)
for label, pts in points.items():
# choose points associated with the desired species
pts = pts[pts['species'] == species_name]