Posts: 4
Threads: 1
Joined: Nov 2019
Nov-19-2019, 04:14 AM
(This post was last modified: Nov-19-2019, 04:41 AM by Larz60+.)
Python: How to categorize the request in different categories for example in 3 categories based on any 3 ex. aa, bb, cc (any):, using KMeans or any other classification technique, I need just categories. help will be highly appreciated. thanks in advance!
import random
class Req():
def __init__(self,reqNum,node_num):
self.reqNum = reqNum
self.location = random.randint(0,node_num//10)
self.firewall_demand = random.randint(300,600)
self.storage_demand = random.randint(100,300)
self.bandwidth_demand = random.randint(200,500)
self.fw_dm = random.randint(200,400)
self.st_dm = random.randint(150,350)
self.bw_dm = random.randint(250,550)
def createSetOfRequest(req_num, node_num):
sr = []
for i in range(0, req_num):
sr.append(Req(i, node_num))
return sr
# (i have to categorise in 3 category, scenario will be like that you can change accordingly, this is just for example)
ns = createSetOfRequest(20,200)
for i in range(0,20):
print(sr[i].reqNum,sr[i].firewall_demand ,sr[i].firewall_demand ,sr[i].bandwidth_demand)
Posts: 32
Threads: 1
Joined: Oct 2019
Nov-19-2019, 11:27 AM
(This post was last modified: Nov-19-2019, 11:28 AM by baquerik.)
I do not understand what you are trying to achieve or what error you are facing.
But the sr variable (bad name by the way) it is defined within the function createSetOfRequest so it will not be reachable from the for loop that you have at the end. You should work with ns.
Posts: 4
Threads: 1
Joined: Nov 2019
sir thanks for your reply, let me more precise, I just need three different categories on the basis of any mentioned parameters using any method of classification. for example KMeans or any other classification method, I want to use these categories in my coding, like in the beginning first category then second and then third.
import random
class Req():
def __init__(self,reqNum,node_num):
self.reqNum = reqNum
self.location = random.randint(0,node_num//10)
self.firewall_demand = random.randint(300,600)
self.storage_demand = random.randint(100,300)
self.bandwidth_demand = random.randint(200,500)
self.fw_dm = random.randint(200,400)
self.st_dm = random.randint(150,350)
self.bw_dm = random.randint(250,550)
Posts: 2,343
Threads: 62
Joined: Sep 2016
I'm unclear on whether this is a Python question, or a data science question in which you happen to be using Python. Your question may be more appropriate in a data-science dedicated forum (and I don't mean our subforum, since regulars who look there would likely have seen this).
Posts: 4
Threads: 1
Joined: Nov 2019
"""Python: How to categorize the request in different categories for example in 3 categories based on any 3 parameters, aa, bb, cc (any):, using KMeans or any other classification technique, I need just categories. help will be highly appreciated. thanks in advance"""
import random
class Request:
def init(self,reqNum,nodenum):
self.reqNum = reqNum
self.firewalldemand = random.randint(300,600)
self.storagedemand = random.randint(100,300)
self.bandwidthdemand = random.randint(200,500)
def createRequest(reqnum, nodenum):
req = []
for i in range(0, reqnum): req.append(Request(i, nodenum))
return req
Posts: 4
Threads: 1
Joined: Nov 2019
(Nov-25-2019, 09:03 PM)micseydel Wrote: I'm unclear on whether this is a Python question, or a data science question in which you happen to be using Python. Your question may be more appropriate in a data-science dedicated forum (and I don't mean our subforum, since regulars who look there would likely have seen this).
thanks a lot, I already posted there
Posts: 11,891
Threads: 476
Joined: Sep 2016
what happened to your indentation?
Posts: 8,094
Threads: 154
Joined: Sep 2016
(Dec-09-2019, 04:06 AM)PythonLearner703 Wrote: thanks a lot, I already posted there I merged the two threads.
Also I think you misread this part of @micseydel's suggestion: and I don't mean our subforum
Posts: 2,343
Threads: 62
Joined: Sep 2016
(Dec-09-2019, 11:24 AM)buran Wrote: Also I think you misread this part of @micseydel's suggestion: and I don't mean our subforum To clarify, if anyone can answer here then great, I just expect that if it was going to get answered here, it already would have been
|