• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python scipy.interp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scipy.interp函数的典型用法代码示例。如果您正苦于以下问题:Python interp函数的具体用法?Python interp怎么用?Python interp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了interp函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: plot_allkfolds_ROC

def plot_allkfolds_ROC(timestamp, cv, fpr_arr, tpr_arr):

    sns.set(style="white", palette="muted", color_codes=True)

    mean_tpr = 0.0
    mean_fpr = 0.0
    all_roc_auc = []
    bins_roc = np.linspace(0, 1, 300)
    with plt.style.context(('seaborn-muted')):
        fig, ax = plt.subplots(figsize=(10, 8))
        for i, (train, test) in enumerate(cv):
            mean_tpr += interp(bins_roc, fpr_arr[i], tpr_arr[i])
            mean_tpr[0] = 0.0
            mean_fpr += interp(bins_roc, fpr_arr[i], tpr_arr[i])
            mean_fpr[0] = 0.0
            roc_auc = metrics.auc(fpr_arr[i], tpr_arr[i])
            all_roc_auc.append(roc_auc)
            ax.plot(fpr_arr[i], tpr_arr[i], lw=1, label='KFold %d (AUC = %0.2f)' % (i, roc_auc))
        ax.plot([0, 1], [0, 1], '--', color=(0.6, 0.6, 0.6), label='Random')

        mean_tpr /= len(cv)
        mean_tpr[-1] = 1.0
        mean_auc = np.mean(all_roc_auc)
        ax.plot(bins_roc, mean_tpr, 'k--',
             label='Mean ROC (AUC = %0.2f)' % mean_auc, lw=2)

        ax.set_xlim([-0.05, 1.05])
        ax.set_ylim([-0.05, 1.05])
        ax.set_xlabel('False Positive Rate')
        ax.set_ylabel('True Positive Rate')
        ax.set_title('Receiver Operating Characteristic')
        ax.legend(loc="lower right")
        plt.savefig('{}_roc.png'.format(timestamp))
    plt.close('all') 
    return mean_auc
开发者ID:freedomofpress,项目名称:FingerprintSecureDrop,代码行数:35,代码来源:evaluation.py


示例2: e_r_read

    def e_r_read(self, waves):
        p = open("MaterialsDataFiles/" + self.material + ".txt", "r")
        string = p.read()
        p.close()
        e_r = []
        w = []
        n = []
        k = []
        linecounter = 0
        for thisline in string.split("\n"):
            for x in thisline.split():
                if linecounter == 0 and len(x) > 0:
                    w.append(float(x))
                if linecounter == 1 and len(x) > 0:
                    n.append(float(x))
                if linecounter == 2 and len(x) > 0:
                    k.append(float(x))
            linecounter += 1

        # interpolate n&k walues
        n_new = sp.interp(waves, w, n)
        k_new = sp.interp(waves, w, k)
        e_r_new = []
        # calculate epsilon from n&k for every wavelength
        for i in range(len(waves)):
            e_r_new.append(
                n_new[i] ** 2 - k_new[i] ** 2 + 2j * n_new[i] * k_new[i]
            )  # calculate the complex epsilon from n&k

        # not sure anymore why e_r (permittivity) gets appended the waves and e_r_new (complex epsilon)
        e_r.append(waves)
        e_r.append(e_r_new)

        self.permittivity = e_r
开发者ID:pliehm,项目名称:Create-Minima-Database,代码行数:34,代码来源:Sim_Reflection_Minima_matlab_algorith.py


示例3: test_calc_mean

    def test_calc_mean(self):
        vulnerability_set = self.from_xml()

        intensity_level = 9

        expected_w1timbermetal_mean = interp(intensity_level, [8.99, 9.05], [0.13, 0.15])
        expected_w1timbermetal_sigma = expected_w1timbermetal_mean * 0.3
        (w1timbermetal_mean, w1timbermetal_sigma) = vulnerability_set.calc_mean("W1TIMBERMETAL", intensity_level)
        self.assertEqual(
            expected_w1timbermetal_mean,
            w1timbermetal_mean,
            self.msg % (expected_w1timbermetal_mean, w1timbermetal_mean),
        )
        self.assertEqual(
            expected_w1timbermetal_sigma,
            w1timbermetal_sigma,
            self.msg % (expected_w1timbermetal_sigma, w1timbermetal_sigma),
        )

        expected_w1bvmetal_mean = interp(intensity_level, [8.99, 9.05], [0.84, 0.85])
        expected_w1bvmetal_sigma = expected_w1bvmetal_mean * 0.3
        (w1bvmetal_mean, w1bvmetal_sigma) = vulnerability_set.calc_mean("W1BVMETAL", intensity_level)
        self.assertEqual(expected_w1bvmetal_mean, w1bvmetal_mean, self.msg % (expected_w1bvmetal_mean, w1bvmetal_mean))
        self.assertEqual(
            expected_w1bvmetal_sigma, w1bvmetal_sigma, self.msg % (expected_w1bvmetal_sigma, w1bvmetal_sigma)
        )
开发者ID:vipkolon,项目名称:eqrm,代码行数:26,代码来源:test_vulnerability_set.py


示例4: __call__

	def __call__(self,x):
		if issubclass(type(x),list): 
			y=scipy.interp(x,self['x'],self['y']);
		else:
			y=scipy.interp([x],self['x'],self['y']);
			y=y[0];
		return y;
开发者ID:charleseagle,项目名称:Data-Analysis-Software-Python,代码行数:7,代码来源:xydiscretefun.py


示例5: e_r_read

 def e_r_read(self,waves):
     p = open('MaterialsDataFiles/'+self.material + '.txt','r')
     string=p.read()
     p.close()
     e_r=[]
     w=[]
     n=[]
     k=[]
     linecounter=0
     for thisline in string.split('\n'):
         for x in thisline.split():
             if linecounter==0 and len(x)>0:
                 w.append(float(x))
             if linecounter==1 and len(x)>0:
                 n.append(float(x))
             if linecounter==2 and len(x)>0:
                 k.append(float(x))
         linecounter+=1
     
     # interpolate n&k walues 
     n_new=sp.interp(waves,w,n)
     k_new=sp.interp(waves,w,k)
     e_r_new=[]      
     # calculate epsilon from n&k for every wavelength
     for i in range(len(waves)):
         e_r_new.append(n_new[i]**2-k_new[i]**2+2j*n_new[i]*k_new[i]) # calculate the complex epsilon from n&k
     e_r.append(waves)
     e_r.append(e_r_new) 
     
     self.permittivity=e_r
开发者ID:pliehm,项目名称:Simulate_ERISM_measurement,代码行数:30,代码来源:Simulate_ERISM_measurement.py


示例6: w_integral

def w_integral(s,W_ax,Y_ax):
    """
        The integral part of the Bellman-equation.
    """
    function = lambda theta,eps,s: max(interp(s*(theta+eps),W_ax,Y_ax), \
        interp(s*(theta+eps)-COST,W_ax,v_func))*aggPDF(theta)*idiPDF(eps)
    return dblquad(function,MIN_VAL_E,MAX_VAL_E,lambda x: MIN_VAL_AG, lambda x: MAX_VAL_AG, args=(s,))
开发者ID:numeraire92,项目名称:third-assignment,代码行数:7,代码来源:multiprocess_w_func_FINAL.py


示例7: calc_mean

    def calc_mean(self, intensity):
        """
        Calculate mean loss ratio and sigma based on the specified points on
        the curve:
                        |
                        |                                +
                        |                           +
        Mean loss ratio |                     +
                        |               +
                        |            +
                        |          +
                        |         +
                        |        +
                        |       +
                        |    +
                        | +
                        +-----------------------------------
                               Intensity measure level

        For a given intensity, mean loss and sigma is determined by linearly
        interpolating the points on the curve.

        Note that sigma is calculated as cv * mean loss as cv = mean loss/sigma
        """
        mean_loss = interp(intensity,
                           self.intensity_measure_level,
                           self.mean_loss)
        cv = interp(intensity,
                    self.intensity_measure_level,
                    self.coefficient_of_variation)
        # cv = sigma / mean
        sigma = cv * mean_loss

        return (mean_loss, sigma)
开发者ID:wcarthur,项目名称:hazimp,代码行数:34,代码来源:vulnerability_model.py


示例8: __call__

 def __call__(self, z):
     """Parameters: z is a number, sequence or array.
     This method makes an instance f of LinInterp callable,
     so f(z) returns the interpolation value(s) at z.
     """
     if isinstance(z, int) or isinstance(z, float):
         return interp ([z], self.X, self.Y)[0]
     else:
         return interp(z, self.X, self.Y)
开发者ID:npalmer,项目名称:BoundedConsumption,代码行数:9,代码来源:dynsys.py


示例9: interpolate_data

def interpolate_data(data, interpolation_timestep_ms):
	'''
		Interpolates all axes of the data array such that samples occur at equidistant timestamps.
	'''
	samples_count = len(data[:,TIME_AXIS_INDEX])
	timestamps = np.arange(0.0, data[samples_count-1,TIME_AXIS_INDEX], interpolation_timestep_ms, dtype=np.float64)
	interx = scipy.interp(timestamps, data[:,0], data[:,X_AXIS_INDEX])
	intery = scipy.interp(timestamps, data[:,0], data[:,Y_AXIS_INDEX])
	interz = scipy.interp(timestamps, data[:,0], data[:,Z_AXIS_INDEX])
	return np.array([timestamps, interx, intery, interz]).transpose()
开发者ID:AhmedHamedTN,项目名称:SensorLogger,代码行数:10,代码来源:fextractor.py


示例10: get_water_level

def get_water_level(costs_all,link,proba,climat):
	'''extracts water levels. the 'proba' argument is how much frequency is increased because of climate change or el nino''' 
	water = DataFrame(columns=['return_period','water_level','proba'])
	for RP in [5,10,25,50,100,250,500,1000]:
		col = "{}_RP{} (dm)".format(climat,RP)
		water.loc[len(water),:]=[RP/proba,costs_all.ix[(costs_all.scenarioID==str(link))&(costs_all.partial_or_full=="full")&(costs_all.improved_2nd==0),col].values[0],proba]
	inter = water.copy()
	#s = InterpolatedUnivariateSpline(water['return period'], water['water level'],k=1)
	water.loc[len(water),:] = [500,interp([500],inter['return_period'].astype(float), inter['water_level'].astype(float))[0],proba]
	water.loc[len(water),:] = [1000,interp([1000],inter['return_period'].astype(float), inter['water_level'].astype(float))[0],proba]
		
	return water
开发者ID:julierozenberg,项目名称:transport_LAC,代码行数:12,代码来源:functions_economic_analysis_cc.py


示例11: ROC

def ROC(scores):
    # Generate an ROC curve for each fold, ordered by increasing threshold
    roc = scores.groupby('user').apply(lambda x: pd.DataFrame(np.c_[roc_curve(x['genuine'], x['score'])][::-1],
                                                              columns=['far', 'frr', 'threshold']))

    # interpolate to get the same threshold values in each fold
    thresholds = np.sort(roc['threshold'].unique())
    roc = roc.groupby(level='user').apply(lambda x: pd.DataFrame(np.c_[thresholds,
                                                                       interp(thresholds, x['threshold'], x['far']),
                                                                       interp(thresholds, x['threshold'], x['frr'])],
                                                                 columns=['threshold', 'far', 'frr']))
    roc = roc.reset_index(level=1, drop=True).reset_index()
    return roc
开发者ID:vmonaco,项目名称:pohmm,代码行数:13,代码来源:keystroke.py


示例12: tophatfold

def tophatfold(lam, flux, FWHM=0.035):
    lammin=min(lam)
    lammax=max(lam)
    dlambda=FWHM/17.
    interlam=np.arange(lammin,lammax,dlambda)
    interflux=interp(interlam,lam,flux)

    #convovle flux array with gaussian--use smooth
    fold=sp.ndimage.filters.uniform_filter(interflux,size=17)

    #interpolate back to original grid
    fluxfold=interp(lam,interlam,fold)

    return fluxfold
开发者ID:jlustigy,项目名称:coronagraph,代码行数:14,代码来源:convolve_spec.py


示例13: execute

    def execute(self):

        #print 'in CPCT_Interpolate'

        wind_speed_ax = np.cos(self.yaw*np.pi/180.0)**(self.pP/3.0)*self.wind_speed_hub
        # use interpolation on precalculated CP-CT curve
        wind_speed_ax = np.maximum(wind_speed_ax, self.windSpeedToCPCT.wind_speed[0])
        wind_speed_ax = np.minimum(wind_speed_ax, self.windSpeedToCPCT.wind_speed[-1])
        self.CP = interp(wind_speed_ax, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
        self.CT = interp(wind_speed_ax, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)

        # normalize on incoming wind speed to correct coefficients for yaw
        self.CP = self.CP * np.cos(self.yaw*np.pi/180.0)**self.pP
        self.CT = self.CT * np.cos(self.yaw*np.pi/180.0)**2
开发者ID:ewanmac,项目名称:FLORISSE,代码行数:14,代码来源:rotor_components.py


示例14: populate_wing_sections

def populate_wing_sections(avl_wing,suave_wing):
	symm     = avl_wing.symmetric
	sweep    = avl_wing.sweep
	dihedral = avl_wing.dihedral
	span     = suave_wing.spans.projected
	semispan = suave_wing.spans.projected * 0.5 * (2 - symm)
	origin   = suave_wing.origin
	root_section = Section()
	root_section.tag    = 'root_section'
	root_section.origin = origin
	root_section.chord  = suave_wing.chords.root
	root_section.twist  = suave_wing.twists.root
	
	tip_section = Section()
	tip_section.tag  = 'tip_section'
	tip_section.chord = suave_wing.chords.tip
	tip_section.twist = suave_wing.twists.tip
	tip_section.origin = [origin[0]+semispan*np.tan(sweep),origin[1]+semispan,origin[2]+semispan*np.tan(dihedral)]
	
	if avl_wing.vertical:
		temp = tip_section.origin[2]
		tip_section.origin[2] = tip_section.origin[1]
		tip_section.origin[1] = temp
	
	avl_wing.append_section(root_section)
	avl_wing.append_section(tip_section)
	
	if suave_wing.control_surfaces:
		for ctrl in suave_wing.control_surfaces:
			num = 1
			for section in ctrl.sections:
				semispan_fraction = (span/semispan) * section.origins.span_fraction
				s = Section()
				s.chord  = scipy.interp(semispan_fraction,[0.,1.],[root_section.chord,tip_section.chord])
				s.tag    = '{0}_section{1}'.format(ctrl.tag,num)
				s.origin = section.origins.dimensional
				s.origin[0] = s.origin[0] - s.chord*section.origins.chord_fraction
				s.twist  = scipy.interp(semispan_fraction,[0.,1.],[root_section.twist,tip_section.twist])
				c = Control_Surface()
				c.tag     = ctrl.tag
				c.x_hinge = 1. - section.chord_fraction
				c.sign_duplicate = ctrl.deflection_symmetry
				
				s.append_control_surface(c)
				avl_wing.append_section(s)
				num += 1
	
	return avl_wing
开发者ID:Alexandrovich,项目名称:SUAVE,代码行数:48,代码来源:create_avl_datastructure.py


示例15: provideJ

    def provideJ(self):

        #print 'in CPCT_Interpolate - provideJ'
        
         # standard central differencing
        # set step size for finite differencing
        h = 1e-6

        # calculate upper and lower function values
        wind_speed_ax_high_yaw = np.cos((self.yaw+h)*np.pi/180.0)**(self.pP/3.0)*self.wind_speed_hub
        wind_speed_ax_low_yaw = np.cos((self.yaw-h)*np.pi/180.0)**(self.pP/3.0)*self.wind_speed_hub
        wind_speed_ax_high_wind = np.cos(self.yaw*np.pi/180.0)**(self.pP/3.0)*(self.wind_speed_hub+h)
        wind_speed_ax_low_wind = np.cos(self.yaw*np.pi/180.0)**(self.pP/3.0)*(self.wind_speed_hub-h)

        # use interpolation on precalculated CP-CT curve
        wind_speed_ax_high_yaw = np.maximum(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed[0])
        wind_speed_ax_low_yaw = np.maximum(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed[0])
        wind_speed_ax_high_wind = np.maximum(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed[0])
        wind_speed_ax_low_wind = np.maximum(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed[0])

        wind_speed_ax_high_yaw = np.minimum(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed[-1])
        wind_speed_ax_low_yaw = np.minimum(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed[-1])
        wind_speed_ax_high_wind = np.minimum(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed[-1])
        wind_speed_ax_low_wind = np.minimum(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed[-1])

        CP_high_yaw = interp(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
        CP_low_yaw = interp(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
        CP_high_wind = interp(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)
        CP_low_wind = interp(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CP)

        CT_high_yaw = interp(wind_speed_ax_high_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
        CT_low_yaw = interp(wind_speed_ax_low_yaw, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
        CT_high_wind = interp(wind_speed_ax_high_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)
        CT_low_wind = interp(wind_speed_ax_low_wind, self.windSpeedToCPCT.wind_speed, self.windSpeedToCPCT.CT)

        # normalize on incoming wind speed to correct coefficients for yaw
        CP_high_yaw = CP_high_yaw * np.cos((self.yaw+h)*np.pi/180.0)**self.pP
        CP_low_yaw = CP_low_yaw * np.cos((self.yaw-h)*np.pi/180.0)**self.pP
        CP_high_wind = CP_high_wind * np.cos((self.yaw)*np.pi/180.0)**self.pP
        CP_low_wind = CP_low_wind * np.cos((self.yaw)*np.pi/180.0)**self.pP

        CT_high_yaw = CT_high_yaw * np.cos((self.yaw+h)*np.pi/180.0)**2
        CT_low_yaw = CT_low_yaw * np.cos((self.yaw-h)*np.pi/180.0)**2
        CT_high_wind = CT_high_wind * np.cos((self.yaw)*np.pi/180.0)**2
        CT_low_wind = CT_low_wind * np.cos((self.yaw)*np.pi/180.0)**2

        # compute derivative via central differencing and arrange in sub-matrices of the Jacobian
        dCP_dyaw = np.eye(self.nTurbines)*(CP_high_yaw-CP_low_yaw)/(2.0*h)
        dCP_dwind = np.eye(self.nTurbines)*(CP_high_wind-CP_low_wind)/(2.0*h)
        dCT_dyaw = np.eye(self.nTurbines)*(CT_high_yaw-CT_low_yaw)/(2.0*h)
        dCT_dwind = np.eye(self.nTurbines)*(CT_high_wind-CT_low_wind)/(2.0*h)

        # compile full Jacobian from sub-matrices
        dCP = np.hstack((dCP_dyaw, dCP_dwind))
        dCT = np.hstack((dCT_dyaw, dCT_dwind))
        J = np.vstack((dCP, dCT))

        return J
开发者ID:ewanmac,项目名称:FLORISSE,代码行数:58,代码来源:rotor_components.py


示例16: crossval_roc

def crossval_roc(X, y):
    cv = StratifiedKFold(y, n_folds=10)
    clf = RandomForestClassifier()

    mean_tpr = 0.0
    mean_fpr = np.linspace(0, 1, 100)
    all_tpr = []

    for i, (train, test) in enumerate(cv):
        fitted = clf.fit(X[train], y[train])
        probas_ = fitted.predict_proba(X[test])
        scored_ = fitted.predict(X[test])
        # Compute ROC curve and area the curve
        fpr, tpr, thresholds = roc_curve(y[test], probas_[:, 1])
        mean_tpr += interp(mean_fpr, fpr, tpr)
        mean_tpr[0] = 0.0
        #roc_auc = auc(fpr, tpr)
        roc_auc = roc_auc_score(scored_, y[test], average="micro")
        #plt.plot(fpr, tpr, lw=1, label='ROC fold %d (area = %0.2f)' % (i, roc_auc))


    mean_tpr /= len(cv)
    mean_tpr[-1] = 1.0
    mean_auc = auc(mean_fpr, mean_tpr)
    return plt.plot(mean_fpr, mean_tpr, 
                    label='Mean ROC (area = %0.2f)' % mean_auc, lw=1)
开发者ID:elipapa,项目名称:SLiMEbook,代码行数:26,代码来源:SLiMEbook.py


示例17: predictForTarget

def predictForTarget(target):
    modTargets = numpy.array([(-1.0, 1.0)[x == target] for x in targets])

    mean_tpr = 0.0
    mean_fpr = numpy.linspace(0, 1, 100)

    for trainIndices, testIndices in cv:
        if algorithm.startswith("svm"):
            clf = sklearn.svm.SVC(C=1.0, kernel=algorithm.replace("svm", ""), gamma=0.0, shrinking=True, probability=True, tol=0.001, cache_size=200, class_weight='auto', verbose=False, max_iter=-1, random_state=0)

        trainData = data[trainIndices,]
        trainTargets = modTargets[trainIndices]
        testData = data[testIndices,]
        testTargets = modTargets[testIndices]

        model = clf.fit(trainData, trainTargets)
        probs = model.predict_proba(testData)[:,1]

        fpr, tpr, thresholds = sklearn.metrics.roc_curve(testTargets, probs)
        mean_tpr += scipy.interp(mean_fpr, fpr, tpr)
        mean_tpr[0] = 0.0
        roc_auc = sklearn.metrics.auc(fpr, tpr)

    mean_tpr /= len(cv)
    mean_tpr[-1] = 1.0

    return sklearn.metrics.auc(mean_fpr, mean_tpr)
开发者ID:srp33,项目名称:GSOA,代码行数:27,代码来源:Predict.py


示例18: _read_iop_from_file

    def _read_iop_from_file(self, file_name):
        """
        Generic IOP reader that interpolates the iop to the common wavelengths defined in the constructor

        returns: interpolated iop
        """
        lg.info('Reading :: ' + file_name + ' :: and interpolating to ' + str(self.wavelengths))

        if os.path.isfile(file_name):
            iop_reader = csv.reader(open(file_name), delimiter=',', quotechar='"')
            wave = scipy.float32(iop_reader.next())
            iop = scipy.zeros_like(wave)
            for row in iop_reader:
                iop = scipy.vstack((iop, row))

            iop = scipy.float32(iop[1:, :])  # drop the first row of zeros
        else:
            lg.exception('Problem reading file :: ' + file_name)
            raise IOError

        try:
            int_iop = scipy.zeros((iop.shape[0], self.wavelengths.shape[1]))
            for i_iter in range(0, iop.shape[0]):
                # r = scipy.interp(self.wavelengths[0, :], wave, iop[i_iter, :])
                int_iop[i_iter, :] = scipy.interp(self.wavelengths, wave, iop[i_iter, :])
            return int_iop
        except IOError:
            lg.exception('Error interpolating IOP to common wavelength')
            return -1
开发者ID:marrabld,项目名称:bootstrappy,代码行数:29,代码来源:deconv.py


示例19: plot_roc_cv

def plot_roc_cv(classifier, X, y, cv):
    '''
    cv = KFold(len(y),n_folds=5)
    '''
    mean_tpr = 0.0
    mean_fpr = np.linspace(0, 1, 100)
    all_tpr = []

    for i, (train, test) in enumerate(cv):
        probas_ = classifier.fit(X[train], y[train]).predict_proba(X[test])
        # Compute ROC curve and area the curve
        fpr, tpr, thresholds = roc_curve(y[test], probas_[:, 1])
        mean_tpr += interp(mean_fpr, fpr, tpr)
        mean_tpr[0] = 0.0
        roc_auc = auc(fpr, tpr)
        plt.plot(fpr, tpr, lw=1, label='ROC fold %d (area = %0.2f)' % (i, roc_auc))

    plt.plot([0, 1], [0, 1], '--', color=(0.6, 0.6, 0.6), label='Luck')

    mean_tpr /= len(cv)
    mean_tpr[-1] = 1.0
    mean_auc = auc(mean_fpr, mean_tpr)
    plt.plot(mean_fpr, mean_tpr, 'k--',
             label='Mean ROC (area = %0.2f)' % mean_auc, lw=2)

    plt.xlim([-0.05, 1.05])
    plt.ylim([-0.05, 1.05])
    plt.xlabel('False Positive Rate')
    plt.ylabel('True Positive Rate')
    plt.title('Receiver operating characteristic example')
    plt.legend(loc="lower right")
    plt.show()
开发者ID:joyce-duan,项目名称:ml_helper,代码行数:32,代码来源:model_eval_plot.py


示例20: bellman_operator

    def bellman_operator(self, w, compute_policy=False):
        """
        The approximate Bellman operator, which computes and returns the 
        updated value function Tw on the grid points.

        Parameters
        ==========
            w : a flat NumPy array with len(w) = len(grid)

        The vector w represents the value of the input function on the grid
        points.

        """
        # === Apply linear interpolation to w === #
        Aw = lambda x: interp(x, self.grid, w)  

        if compute_policy:
            sigma = np.empty(len(w))

        # === set Tw[i] equal to max_c { u(c) + beta w(f(k_i) - c)} === #
        Tw = np.empty(len(w))
        for i, k in enumerate(self.grid):
            objective = lambda c:  - self.u(c) - self.beta * Aw(self.f(k) - c)
            c_star = fminbound(objective, 1e-6, self.f(k))
            if compute_policy:
                # sigma[i] = argmax_c { u(c) + beta w(f(k_i) - c)} 
                sigma[i] = c_star
            Tw[i] = - objective(c_star)

        if compute_policy:
            return Tw, sigma
        else:
            return Tw
开发者ID:28ideas,项目名称:quant-econ,代码行数:33,代码来源:optgrowth.py



注:本文中的scipy.interp函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python scipy.isfinite函数代码示例发布时间:2022-05-27
下一篇:
Python scipy.inner函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap