当前位置: 首页>>代码示例>>Python>>正文


Python pyplot.matshow函数代码示例

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


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

示例1: classifykNN

def classifykNN():
    print 'Classify kNN'
    target_names = ['unacc', 'acc','good','v-good']
    df = pd.read_csv("data/cars-cleaned.txt", delimiter=",");    
    print df
    print df.dtypes
    df_y = df['accept']
    df_x = df.ix[:,:-1]

    #print df_y
    #print df_x
    train_y, test_y, train_x, test_x = train_test_split(df_y, df_x, test_size = 0.3, random_state=33)
    
    clf = KNeighborsClassifier(n_neighbors=3)
    tstart=time.time()
    model = clf.fit(train_x, train_y)
    print "training time:", round(time.time()-tstart, 3), "seconds"
    y_predictions = model.predict(test_x)
    print "Accuracy : " , model.score(test_x, test_y)
    #print y_predictions
    c_matrix = confusion_matrix(test_y,y_predictions)
    print "confusion matrix:"
    print c_matrix

    print "Nearest Neighbors probabilities"
    print model.predict_proba(test_x)
    
    plt.matshow(c_matrix)
    plt.colorbar();
    tick_marks = np.arange(len(target_names))
    plt.xticks(tick_marks, target_names, rotation=45)
    plt.yticks(tick_marks, target_names)    
    plt.ylabel('true label')
    plt.xlabel('predicted label')
    plt.show()
开发者ID:venukanaparthy,项目名称:MachineLearning,代码行数:35,代码来源:knn_classify.py

示例2: classify

def classify():
    print 'Classify SVM'
    target_names = ['unacc', 'acc','good','v-good']
    df = pd.read_csv("data/cars-cleaned.txt", delimiter=",");    
    print df
    print df.dtypes
    df_y = df['accept']
    df_x = df.ix[:,:-1]
   
    train_y, test_y, train_x, test_x = train_test_split(df_y, df_x, test_size = 0.3, random_state=33)
    
    clf = svm.SVC(kernel="linear", C=0.01)
    tstart=time.time()
    model = clf.fit(train_x, train_y)
    print "training time:", round(time.time()-tstart, 3), "seconds"
    y_predictions = model.predict(test_x)
    print "Accuracy : " , model.score(test_x, test_y)
    c_matrix = confusion_matrix(test_y,y_predictions)
    print "confusion matrix:"
    print c_matrix

    plt.matshow(c_matrix)
    plt.colorbar();
    tick_marks = np.arange(len(target_names))
    plt.xticks(tick_marks, target_names, rotation=45)
    plt.yticks(tick_marks, target_names)    
    plt.ylabel('true label')
    plt.xlabel('predicted label')
    plt.show()
开发者ID:venukanaparthy,项目名称:MachineLearning,代码行数:29,代码来源:svm_classify.py

示例3: export_pdf

def export_pdf(data, output, gradient=True):
    """Exports the data as a heatmap to the file specified by output (.pdf). The gradient
	marker specifies if the color in the heatmap should be a gradient that shows the
	fold change score, or as binary red/white colors with a cutoff for maximum fold-change
	score to be considered a hit.
	"""
    bacteria = sorted(data.values()[0].keys())
    matrix = np.zeros((len(data), len(bacteria)))
    rows = sorted(
        data.keys(),
        key=lambda w: np.sum([d ** 3 for d in data[w].values()]) / (len([d for d in data[w].values() if d < 0.3]) + 1),
    )
    for wind, well in enumerate(rows):
        for bind, bacterium in enumerate(bacteria):
            if gradient:
                matrix[(wind, bind)] = data[well][bacterium]
            else:
                matrix[(wind, bind)] = 0 if data[well][bacterium] < 0.3 else 0.5
    plt.matshow(matrix, cmap=plt.get_cmap("RdYlGn"), vmin=0, vmax=1)
    plt.xticks(range(len(bacteria)), bacteria, rotation=90)
    plt.yticks(range(len(rows)), rows)
    ax = plt.gca()
    for posi in ax.spines:
        ax.spines[posi].set_color("none")
    ax.tick_params(labelcolor="k", top="off", bottom="off", left="off", right="off")
    fig = plt.gcf()
    fig.set_size_inches(10, 100)
    plt.savefig(output + ".pdf", bbox_inches="tight", dpi=200)
    plt.close()
开发者ID:kenjsc,项目名称:CAMpping,代码行数:29,代码来源:biomap_crude.py

示例4: plot_confusion_matrix

def plot_confusion_matrix(cm):
	pl.matshow(cm)
	pl.title('Confusion matrix')
	pl.colorbar()
	pl.ylabel('True label')
	pl.xlabel('Predicted label')
	pl.show()
开发者ID:mCalde,项目名称:marsupio,代码行数:7,代码来源:plotting.py

示例5: generate_single_funnel_test_data

def generate_single_funnel_test_data( excitation_angles, emission_angles, \
                                          md_ex=0, md_fu=1, \
                                          phase_ex=0, phase_fu=0, \
                                          gr=1.0, et=1.0 ):

    ex, em = np.meshgrid( excitation_angles, emission_angles )

    alpha = 0.5 * np.arccos( .5*(((gr+2)*md_ex)-gr) )

    ph_ii_minus = phase_ex - alpha
    ph_ii_plus  = phase_ex + alpha
    
    print ph_ii_minus
    print ph_ii_plus

    Fnoet  =    np.cos( ex-ph_ii_minus )**2 * np.cos( em-ph_ii_minus )**2
    Fnoet += gr*np.cos( ex-phase_ex )**2    * np.cos( em-phase_ex )**2
    Fnoet +=    np.cos( ex-ph_ii_plus )**2  * np.cos( em-ph_ii_plus )**2
        
    Fnoet /= (2+gr)
    
    Fet   = .25 * (1+md_ex*np.cos(2*(ex-phase_ex))) \
        * (1+md_fu*np.cos(2*(em-phase_fu-phase_ex)))
    
    
    Fem = et*Fet + (1-et)*Fnoet


    import matplotlib.pyplot as plt
    plt.interactive(True)
    plt.matshow( Fem, origin='bottom' )
    plt.colorbar()
开发者ID:kiwimatto,项目名称:2dpolim-analysis,代码行数:32,代码来源:util_misc.py

示例6: test_initialize_at_truth

def test_initialize_at_truth():
    global alpha, beta, num_topics, num_vocab, document_lengths, \
            doc_topic, topic_word, docs, model
    alpha = 5.
    beta = 20.
    num_topics = 20
    num_vocab = 1000
    document_lengths = [100]*1000

    doc_topic, topic_word, docs = generate_synthetic(alpha,beta,
            num_topics,num_vocab,document_lengths)

    model = lda.CollapsedSampler(alpha,beta,num_topics,num_vocab)
    model.add_documents_spmat(docs)

    # initialize at truth
    model.document_topic_counts = (model.document_topic_counts.sum(1)[:,None] * doc_topic).round()
    model.topic_word_counts = (model.topic_word_counts.sum(1)[:,None] * topic_word).round()

    model.resample(1000)

    plt.matshow(topic_word[:20,:20])
    plt.title('true topic_word on first 20 words')
    plt.matshow(model.topic_word_counts[:20,:20])
    plt.title('topic_word counts on first 20 words')
开发者ID:mattjj,项目名称:yaldapy,代码行数:25,代码来源:test.py

示例7: TestSVM

def TestSVM(features, labels, silence=True):
    X_train = features[0:1600,:]
    Y_train = labels[0:1600]

    X_test = features[1600:,:]
    Y_test = labels[1600:]

    clf = SVM.SVC()
    clf.fit(X_train, Y_train)

    predictions = clf.predict(X_test)  

    error = np.mean(abs(predictions-Y_test))

    cm = confusion_matrix(Y_test, predictions)

    cm_sum = np.sum(cm, axis=1)

    cm_mean = cm.T / cm_sum
    cm_mean = cm_mean.T
    
    if silence==False:
        plt.matshow(cm_mean)
        plt.title('Confusion matrix')
        plt.colorbar()
        plt.ylabel('True label')
        plt.xlabel('Predicted label')
        plt.show()
        
    return error, cm_mean
开发者ID:IreneFidone,项目名称:TUC-Team,代码行数:30,代码来源:TestSVM.py

示例8: compare_autoencoder_outputs

def compare_autoencoder_outputs(imgs, model, indices=[0], img_dim=(28, 28)):
    pred = model.predict(imgs)
    for i in indices:
        tup = (imgs[i].reshape(img_dim), pred[i].reshape(img_dim))
        plt.matshow(tup[0])
        plt.matshow(tup[1])
    plt.show()
开发者ID:imauser,项目名称:Autoencoders-with-keras,代码行数:7,代码来源:main.py

示例9: makeConfusionMatrix

def makeConfusionMatrix(n=100):
	# import some data to play with
	trainingdata = sio.loadmat('train.mat')
	X = np.swapaxes(trainingdata['train_images'].reshape(784,60000), 0, 1)
	y = np.array(trainingdata['train_labels']).transpose()[0]
	# Split the data into a training set and a test set
	X_train, X_test, y_train, y_test = train_test_split(X, y, train_size=n/60000.0)

	# Run classifier
	classifier = svm.SVC(kernel='linear')
	y_pred = classifier.fit(X_train, y_train).predict(X_test)
	# Compute confusion matrix
	cm = confusion_matrix(y_test, y_pred)

	print(cm)

	# Show confusion matrix in a separate window
	plt.matshow(cm)
	plt.title('Confusion matrix')
	plt.colorbar()
	plt.ylabel('True label')
	plt.xlabel('Predicted label')
	plt.savefig('matrix'+str(n))
	plt.show()
	return
开发者ID:kevinchau321,项目名称:189,代码行数:25,代码来源:digitSVM.py

示例10: verify_gradient

def verify_gradient(f, x, eps=1e-4, tol=1e-6, **kwargs):
    """
    Compares the numerical and analytical gradients.
    """
    # print
    fval, fgrad = f(x=x, **kwargs)
    # print fval, fgrad.shape
    # bbbbbbbb
    ngrad = numerical_gradient(f=f, x=x, eps=eps, tol=tol, **kwargs)

    fgradnorm = numpy.sqrt(numpy.sum(fgrad**2))
    ngradnorm = numpy.sqrt(numpy.sum(ngrad**2))
    diffnorm = numpy.sqrt(numpy.sum((fgrad-ngrad)**2))
    # print fval.shape
    plt.matshow(fgrad)
    plt.show()
    plt.matshow(ngrad)
    plt.show()
    if fgradnorm > 0 or ngradnorm > 0:
        norm = numpy.maximum(fgradnorm, ngradnorm)
        if not (diffnorm < tol or diffnorm/norm < tol):
            raise Exception("Numerical and analytical gradients "
                            "are different: %s != %s!" % (ngrad, fgrad))
    else:
        if not (diffnorm < tol):
            raise Exception("Numerical and analytical gradients "
                            "are different: %s != %s!" % (ngrad, fgrad))
    return True
开发者ID:franciscovargas,项目名称:MLPHonoursExtension,代码行数:28,代码来源:utils.py

示例11: coloc

def coloc(dataR, dataG):
    #returns heatmap for colocalization based on the angle in the red- green value plot
    #regions with low intensity are filterd out

    if dataR.shape != dataG.shape:
        print('images must have same shape')
        return 0

    tol=0.02
    dataB = np.zeros(dataR.shape)
    dataB[...,0]=np.tan(dataR[...,2]/dataG[...,1])
    dataB[...,0]=np.where((dataB[...,0]-np.pi/2.)**2>tol,0,dataB[...,0])
    maskG=np.where(dataG[...,1]<np.mean(dataG[...,1]),0,dataG[...,1])
    maskR=np.where(dataR[...,2]<np.mean(dataR[...,2]),0,dataR[...,2])
    from matplotlib import pyplot
    #pyplot.matshow(maskR)
    #pyplot.show()
    #pyplot.matshow(maskG)
    #pyplot.show()

    dataB[...,0]=dataB[...,0]*maskG*maskR
    dataB=dataB*255/np.max(dataB)
    dataB = np.array(dataB, dtype=np.uint8)
    print(np.mean(dataB[...,0]))


    plot.matshow(dataB[...,0])
    plot.show()

    return dataB
开发者ID:ukoethe,项目名称:simple-STORM,代码行数:30,代码来源:colocalizationDetection.py

示例12: test

def test(training_file, testing_file):
    X,y = train.process_training_examples(training_file)
    X_test, y_test = train.process_training_examples(testing_file)

    lin_svm = train.train_linear_svm(X, y)
    linear_svm_accuracy = test_with(lin_svm, X_test, y_test)
    print("LinearSVM has classification accuracy of {}%".format(100 * linear_svm_accuracy))

    rbf_svm = train.train_rbf_svm(X, y)
    rbf_svm_accuracy = test_with(rbf_svm, X_test, y_test)
    print("RBF-SVM has classification accuracy of {}%".format(100 * rbf_svm_accuracy))

    nbc = train.train_naive_bayes(X, y)
    nb_accuracy = test_with(nbc, X_test, y_test)
    print("Multinomial Naive Bayes has classification accuracy of {}%".format(100 * nb_accuracy))

    lda = train.train_lda(X, y)
    lda_accuracy = test_with(lda, X_test, y_test)
    print("LDA has classification accuracy of {}%".format(100 * lda_accuracy))

    #Print SVM confusion matrix
    y_pred = lin_svm.predict(X_test)
    cm = confusion_matrix(y_test, y_pred)
    plt.matshow(cm)
    plt.title('Confusion matrix for SVM Classification of File Fragment Types')
    #plt.colorbar()
    plt.ylabel('True File Type')
    plt.xlabel('Predicted File Type')
    plt.show()
开发者ID:andreweduffy,项目名称:carveml,代码行数:29,代码来源:test.py

示例13: show_confusion_matrix

def show_confusion_matrix(X, y):
    """docstring for show_confusion_matrix"""

    print "show matrix..."
    # Split the data into a training set and a test set
    X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0, test_size=.1)

    print "running classifier...."
    # Run classifier
    classifier = svm.SVC()
    y_pred = classifier.fit(X_train, y_train).predict(X_test)

    print "compute confusion matrix..."
    # Compute confusion matrix
    cm = confusion_matrix(y_test, y_pred)

    cm_sum = np.sum(cm, axis=1).T

    cm_ratio = cm / cm_sum.astype(float)[:, np.newaxis]

    print(cm_ratio)
    print cm
    print cm_sum

    print "plot matrix..."
    # Show confusion matrix in a separate window
    plt.matshow(cm_ratio)
    plt.title('Confusion matrix')
    plt.colorbar()
    plt.ylabel('True label')
    plt.xlabel('Predicted label')
    plt.show()
开发者ID:ymnliu,项目名称:cyto_lib,代码行数:32,代码来源:train_test.py

示例14: calc_field_OneDistance

 def calc_field_OneDistance(self, distance, n_z_points, temp_field=None,
                            plot_matrix=False):
     if temp_field is not None:
         old_field = [self.do_static, self.do_induction, self.do_radiation]
         self.set_fields(temp_field)
         
     Z_array, dz = np.linspace(0, self.channel_height, n_z_points,
                               retstep=True)
     
     min_t = self.min_starttime + distance/C
     max_t = self.max_endtime + np.sqrt(distance*distance +
                              self.channel_height*self.channel_height)/C
     n_t_points = int((max_t-min_t)/self.dt)+1
     
     T_array = min_t + np.arange(n_t_points)*self.dt
     
     field_matrix=np.zeros((n_t_points,n_z_points))
     
     for z_i in range(n_z_points):
         self.integrand(Z_array[z_i], distance, min_t, field_matrix[:,z_i])
         
     Es=-simps(field_matrix, dx=dz)/two_pi_e0
     
     if temp_field!=None:
         self.do_static, self.do_induction, self.do_radiation=old_field
         
     if plot_matrix:
         plt.matshow(-field_matrix/two_pi_e0)
         plt.colorbar()
         plt.show()
     
     return T_array, Es
开发者ID:EdwardBetts,项目名称:iclrt_tools,代码行数:32,代码来源:wave_model.py

示例15: marg_mult

def marg_mult(model, db, samples, burn=0, filename=None, n5=False):
    """
    generates histogram for marginal distribution of posterior multiplicities.

    :param model: TorsionFitModel
    :param db: pymc.database for model
    :param samples: length of trace
    :param burn: int. number of steps to skip
    :param filename: filename for plot to save
    """
    if n5:
        multiplicities = tuple(range(1, 7))
    else:
        multiplicities = (1, 2, 3, 4, 6)
    mult_bitstring = []
    for i in model.pymc_parameters.keys():
        if i.split('_')[-1] == 'bitstring':
            mult_bitstring.append(i)
    if n5:
        histogram = np.zeros((len(mult_bitstring), samples, 5))
    else:
        histogram = np.zeros((len(mult_bitstring), samples, 5))

    for m, torsion in enumerate(mult_bitstring):
        for i, j in enumerate(db.trace('%s' % torsion)[burn:]):
            for k, l in enumerate(multiplicities):
                if 2**(l-1) & int(j):
                    histogram[m][i][k] = 1

    plt.matshow(histogram.sum(1), cmap='Blues',  extent=[0, 5, 0, 20]), plt.colorbar()
    plt.yticks([])
    plt.xlabel('multiplicity term')
    plt.ylabel('torsion')
    if filename:
        plt.savefig(filename)
开发者ID:ChayaSt,项目名称:torsionfit,代码行数:35,代码来源:plots.py


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