KNN algorithm to achieve cloud python

Cloud Computing Overview and KNN algorithm using python language

 

Cloud Computing Overview

Introduction to Cloud Computing (Baidu Encyclopedia)

Cloud Services Overview ----- types of cloud services

Application Layer - SaaS software as a service, such as: Google APPS, SoftWare, Services;

Internet layer corresponds to a service such as internet PaaS: IBM Bluemix, Google APPEngine, Force.com ;

Layer infrastructure corresponds IaaS Infrastructure services such as: Amazon n EC2, IBM Blue Cloud , Sun Grid;

Virtualization layer corresponding to a service in conjunction with the hardware PaaS hardware service, including hardware detection and cluster server services.

So cloud computing in accordance with the type of service can be divided into three categories: Iaas, Paas, Saas three categories

The meaning is:

Iaas (Infrastructure-as-a- Service): Infrastructure as a Service . Consumers can obtain service from a good computer infrastructure over the Internet.

Paas (Platform-as-a- Service): Platform as a Service . PaaS actually refers to the software development platform as a service, presented to the user in a SaaS model. Therefore, PaaS is also a SaaS application model. However, the emergence of PaaS SaaS can accelerate the development of, in particular, accelerate the development of SaaS applications.

Saas (Software-as-a- Service): software as a service . It is a mention providing Internet software mode, users do not need to buy software, but leased to the provider of Web-based software to manage business activities. Compared with traditional software, SaaS solutions have significant advantages, including lower upfront costs, ease of maintenance, such as the use of rapid deployment.

 

Today, the use of cloud lab completed the experiment, the way to find out about the prior knowledge of cloud computing to do a comb. In fact, the use of the cloud is very convenient, do not worry about the impact on computer performance configuration of the experiment itself, just focus on doing their own thing, the experience is very convenient, cloud computing is the future trend of development of it.

KNN algorithm description: https://www.cnblogs.com/ybjourney/p/4702562.html

In fact, in the "Data Analysis" This course itself learned discriminant analysis, discriminant achieve a lot of analytical methods, such as distance discriminant, a Bayesian discrimination, Fisher discrimination, KNN algorithm belongs to a distance-discrimination. 

 

The following is a simple classification algorithm of KNN in the cloud environment, using PyCharm:

The first file KNN.py 

# coding=utf-8

from numpy import *
import operator

def createDataSet():
    group = array([[1.0, 0.9], [1.0, 1.0], [0.1, 0.2], [0.0, 0.1]])
    labels = ['A', 'A', 'B', 'B']
    return group, labels


def KNNClassify(newInput, dataSet, labels, k):
    numSamples = dataSet.shape[0]   # shape[0]表示行数

    diff = tile(newInput, (numSamples, 1)) - dataSet  # 按元素求差值
    squaredDiff = diff ** 2  # 将差值平方
    squaredDist = sum(squaredDiff, axis = 1)   # 按行累加
    distance = squaredDist ** 0.5  # 将差值平方和求开方,即得距离

    sortedDistIndices = argsort(distance)
    classCount = {} # define a dictionary (can be append element)
    for i in range(k):
        voteLabel = labels[sortedDistIndices[i]]
        classCount[voteLabel] = classCount.get(voteLabel, 0) + 1

    maxCount = 0
    for key, value in classCount.items():
        if value > maxCount:
            maxCount = value
            maxIndex = key

    return maxIndex

The second file KNNTest.py 

# coding=utf-8
import KNN
from numpy import *
dataSet, labels = KNN.createDataSet()
testX = array([1.2, 1.0])
k = 3
outputLabel = KNN.KNNClassify(testX, dataSet, labels, 3)
print("Your input is:", testX, "and classified to class: ", outputLabel)

testX = array([0.1, 0.3])
outputLabel = KNN.KNNClassify(testX, dataSet, labels, 3)
print("Your input is:", testX, "and classified to class: ", outputLabel)

The results Screenshot 

 

 

 

Guess you like

Origin blog.csdn.net/weixin_44961794/article/details/90737173