머신러닝 프로그래밍 6주차-Basic classification with random variables
Basic classification with random variables
import numpy as np
import matplotlib.pyplot as plt
mass1 = 0.5
mass2 = 1.0
sigma1 = 0.05
sigma2 = 0.2
masses1 = np.random.normal(mass1, sigma1,1000)#정규분포
masses2 = np.random.normal(mass2, sigma2,1000)
masses1
array([0.48085962, 0.39529791, 0.49207845, 0.53610742, 0.47889003,
0.44878694, 0.58693865, 0.48729507, 0.51385434, 0.53489413,
0.52420503, 0.45550835, 0.42723844, 0.52990696, 0.46041514,
0.49170191, 0.48628479, 0.55004327, 0.56146501, 0.42357572,
0.46390597, 0.47782139, 0.43151662, 0.5477146 , 0.49391723,
0.46414446, 0.46005639, 0.62278563, 0.54547312, 0.50060325,
0.44835484, 0.54164596, 0.61677485, 0.64035879, 0.49796053,
0.41104766, 0.45769303, 0.43998742, 0.44979714, 0.54090414,
0.4819793 , 0.45683165, 0.51148304, 0.54011369, 0.53720023,
0.48761831, 0.45541782, 0.54378533, 0.48638293, 0.51144045,
0.4813313 , 0.48019784, 0.42427419, 0.47522839, 0.55090631,
0.51450045, 0.45262232, 0.50379519, 0.57089619, 0.48978224,
0.49917363, 0.43024215, 0.5107406 , 0.56983783, 0.53756989,
0.58026245, 0.50519425, 0.49145439, 0.54954404, 0.53077221,
0.51514988, 0.51607497, 0.57447157, 0.533438 , 0.58433977,
0.56319595, 0.48602384, 0.43221065, 0.54939061, 0.47704535,
0.45181661, 0.4458255 , 0.49630458, 0.55156519, 0.48441557,
0.55464087, 0.50602159, 0.50926559, 0.53356453, 0.545663 ,
0.52271166, 0.47266429, 0.57685083, 0.45657014, 0.41532355,
0.47454176, 0.57238203, 0.54517016, 0.55372412, 0.4617997 ,
0.53770872, 0.53475772, 0.57815026, 0.31185088, 0.53351859,
0.52156893, 0.44716874, 0.45143841, 0.43097594, 0.56795903,
0.53531341, 0.56102112, 0.51640365, 0.52617388, 0.54392599,
0.44544199, 0.44496283, 0.55566186, 0.5190187 , 0.52962524,
0.4727275 , 0.54606949, 0.46735826, 0.52826997, 0.48915107,
0.47869666, 0.49356227, 0.51680141, 0.4008277 , 0.46215068,
0.46956561, 0.52501878, 0.47297663, 0.46007157, 0.55065407,
0.47146741, 0.49241285, 0.43106903, 0.43135382, 0.4605621 ,
0.38250943, 0.50280166, 0.51207518, 0.59779379, 0.48460375,
0.46171464, 0.43952076, 0.4725214 , 0.45735205, 0.48734903,
0.47915772, 0.42404747, 0.4461709 , 0.50461401, 0.54361768,
0.51829958, 0.50712328, 0.46996361, 0.60317482, 0.4782103 ,
0.57214739, 0.48522058, 0.4394478 , 0.39488105, 0.52518627,
0.53655826, 0.44294381, 0.47563577, 0.56237299, 0.58898817,
0.44996025, 0.54315166, 0.57938679, 0.3926635 , 0.52309584,
0.46486437, 0.41341028, 0.51730144, 0.52032596, 0.53340754,
0.50329487, 0.62303041, 0.53717717, 0.49710891, 0.52164014,
0.50808317, 0.4913547 , 0.53605741, 0.45940546, 0.5233776 ,
0.47519407, 0.51056049, 0.56102632, 0.53420878, 0.50859618,
0.4864267 , 0.54886452, 0.53234004, 0.51203216, 0.47940999,
0.37229445, 0.50031034, 0.50828179, 0.53154238, 0.4703242 ,
0.48476302, 0.46060454, 0.54717345, 0.53498775, 0.4470518 ,
0.39367144, 0.49462999, 0.47662618, 0.51883913, 0.47841749,
0.40853128, 0.45435437, 0.53498362, 0.585224 , 0.5141989 ,
0.52303355, 0.53634189, 0.46474207, 0.47502006, 0.49480594,
0.47422302, 0.52132088, 0.4917995 , 0.50343293, 0.41562328,
0.53140519, 0.54099559, 0.49739501, 0.50932792, 0.44513562,
0.5536379 , 0.54513727, 0.54800364, 0.56954817, 0.44982763,
0.51038821, 0.5508022 , 0.54300394, 0.50598583, 0.46689896,
0.49967503, 0.53922869, 0.47379302, 0.36412655, 0.51690897,
0.54304916, 0.46936314, 0.52531785, 0.56292087, 0.44062074,
0.45139692, 0.57276154, 0.57507749, 0.52792292, 0.54970871,
0.56586348, 0.44757602, 0.41052231, 0.48578904, 0.46913947,
0.55526301, 0.40690872, 0.5426426 , 0.3417497 , 0.47167592,
0.50091903, 0.47471211, 0.55244088, 0.51613349, 0.44210845,
0.51147912, 0.58643795, 0.48731236, 0.57289902, 0.48240725,
0.49530414, 0.52820419, 0.44120304, 0.46607105, 0.52909717,
0.52656591, 0.50349567, 0.50025558, 0.54824334, 0.48913084,
0.53624846, 0.45292888, 0.44957861, 0.52459063, 0.55697174,
0.43759689, 0.59610461, 0.49101453, 0.5754494 , 0.48525135,
0.37561722, 0.49687127, 0.43874704, 0.45650475, 0.49406821,
0.51214484, 0.55164301, 0.51289979, 0.50792813, 0.56081916,
0.50988824, 0.56444756, 0.54826069, 0.48023256, 0.42949689,
0.56339261, 0.57278582, 0.51100874, 0.55135486, 0.49208747,
0.37341738, 0.48841652, 0.50636018, 0.40949689, 0.60064447,
0.45714702, 0.47292366, 0.41926814, 0.44400461, 0.46191325,
0.50070049, 0.52077113, 0.57107244, 0.55308899, 0.45835051,
0.54466041, 0.49464806, 0.51113191, 0.53542739, 0.58541178,
0.54379276, 0.49309271, 0.51273499, 0.41170559, 0.48083428,
0.4889153 , 0.43382984, 0.58369869, 0.61261263, 0.41682597,
0.42890952, 0.46115782, 0.5357529 , 0.49294984, 0.48810269,
0.50915765, 0.45564434, 0.51936449, 0.50668222, 0.37641313,
0.56524095, 0.49750225, 0.45822135, 0.42011837, 0.61233999,
0.4959874 , 0.51116696, 0.50553575, 0.49823305, 0.58108238,
0.51305415, 0.43575943, 0.59206726, 0.47809617, 0.4891317 ,
0.47592122, 0.57235845, 0.57044668, 0.54541996, 0.46894005,
0.4934046 , 0.41656116, 0.51793511, 0.55671517, 0.53891888,
0.48545785, 0.38382408, 0.50908791, 0.46012942, 0.50169329,
0.50324621, 0.58015987, 0.49488592, 0.49744565, 0.49205257,
0.50693136, 0.56050106, 0.47736329, 0.45486145, 0.48365497,
0.61511052, 0.44190441, 0.43397812, 0.54054681, 0.5162681 ,
0.53546594, 0.46278367, 0.53105848, 0.64920849, 0.53652151,
0.46166512, 0.56826167, 0.59064826, 0.55286041, 0.48433637,
0.48762157, 0.51115702, 0.50754214, 0.54725923, 0.48603067,
0.40786278, 0.52837446, 0.47645245, 0.47026879, 0.58274766,
0.51114909, 0.48077023, 0.45727064, 0.58674242, 0.48802607,
0.55280929, 0.38565414, 0.55101975, 0.53334804, 0.48733745,
0.50301774, 0.54208265, 0.5473585 , 0.56034879, 0.46525519,
0.52606717, 0.53556443, 0.48691268, 0.53185356, 0.48144658,
0.53929647, 0.55645509, 0.51617622, 0.48415672, 0.48207904,
0.5292939 , 0.48549222, 0.47632054, 0.50205479, 0.43011243,
0.43832381, 0.50853438, 0.49631502, 0.4317682 , 0.46598662,
0.5198122 , 0.42472486, 0.48887091, 0.50440126, 0.56641206,
0.45234925, 0.4877086 , 0.51073436, 0.434442 , 0.48909958,
0.41119722, 0.47473351, 0.4125149 , 0.53706017, 0.50353513,
0.53059732, 0.4724849 , 0.54358338, 0.49938886, 0.52396921,
0.49827486, 0.55751255, 0.53769963, 0.50702383, 0.4549925 ,
0.50292629, 0.4722953 , 0.44557794, 0.53526627, 0.5306554 ,
0.52675505, 0.53142718, 0.51359777, 0.5319623 , 0.51967874,
0.53418859, 0.48565917, 0.56173175, 0.47823687, 0.53412772,
0.49860659, 0.4513172 , 0.43515542, 0.57237933, 0.44983269,
0.47930498, 0.49222767, 0.50004609, 0.48562411, 0.4057914 ,
0.49830874, 0.45144971, 0.37693802, 0.44377817, 0.44910951,
0.57567354, 0.51024746, 0.56462003, 0.4475983 , 0.46811088,
0.46959748, 0.5149021 , 0.49189445, 0.44513607, 0.49403515,
0.41767592, 0.45140861, 0.4725951 , 0.56948174, 0.45543863,
0.57677104, 0.49868179, 0.51023245, 0.58107528, 0.48694909,
0.43512587, 0.55852721, 0.47193253, 0.52658374, 0.49529112,
0.41004382, 0.48188836, 0.41295361, 0.50563336, 0.55172412,
0.53672823, 0.415196 , 0.53309126, 0.45111155, 0.48058264,
0.4945456 , 0.4719675 , 0.4514245 , 0.42094576, 0.46628792,
0.40607179, 0.39487629, 0.50259104, 0.49408268, 0.48521354,
0.53642475, 0.62610253, 0.52174817, 0.57672746, 0.47989106,
0.56724133, 0.52214627, 0.50332879, 0.47505236, 0.46396059,
0.46941412, 0.46670385, 0.54186219, 0.50773232, 0.50359548,
0.45867792, 0.47890445, 0.50519316, 0.48534553, 0.48457262,
0.54626157, 0.53496509, 0.41215792, 0.58009323, 0.53946081,
0.52817983, 0.54312191, 0.49990855, 0.41735145, 0.44900367,
0.4979759 , 0.63360233, 0.4472056 , 0.51826766, 0.55552239,
0.46869403, 0.50452727, 0.52039733, 0.48079908, 0.50866901,
0.46026291, 0.34406651, 0.61425239, 0.53026096, 0.59206325,
0.46807501, 0.49704095, 0.53540473, 0.51045635, 0.54231423,
0.40722399, 0.43556073, 0.52097441, 0.47480956, 0.50927 ,
0.44883856, 0.50032888, 0.50402094, 0.45735285, 0.45821821,
0.55675203, 0.47687454, 0.53688471, 0.47710723, 0.54745652,
0.53789637, 0.43520645, 0.51076606, 0.47507605, 0.48856554,
0.55374097, 0.50492177, 0.42421583, 0.5263916 , 0.48447477,
0.53751199, 0.50878994, 0.43117847, 0.5029427 , 0.55128571,
0.55507499, 0.52729092, 0.45851927, 0.49865413, 0.53655528,
0.53512937, 0.48919308, 0.4809988 , 0.42749783, 0.46680385,
0.5224332 , 0.51937841, 0.5317389 , 0.51694877, 0.4888053 ,
0.51952321, 0.5300682 , 0.44640494, 0.4364902 , 0.51192223,
0.51837926, 0.55659877, 0.47374608, 0.44302766, 0.53474436,
0.44748077, 0.4431698 , 0.49363196, 0.44224401, 0.46066023,
0.51446807, 0.48582525, 0.45911657, 0.55407568, 0.58062533,
0.42014664, 0.49425231, 0.42231956, 0.4375304 , 0.50368868,
0.54725135, 0.50943435, 0.55590078, 0.50675481, 0.45341262,
0.50843332, 0.57471915, 0.52825537, 0.48410296, 0.45766223,
0.4581939 , 0.58235258, 0.47876486, 0.49990446, 0.53496503,
0.59690342, 0.53332646, 0.45896003, 0.55236187, 0.49655218,
0.54237907, 0.4984605 , 0.39284843, 0.45008177, 0.40499666,
0.46692849, 0.45471479, 0.57023741, 0.51816844, 0.4361427 ,
0.55286141, 0.48912668, 0.41669452, 0.49930435, 0.48572432,
0.46590044, 0.51943297, 0.57581824, 0.47185001, 0.52361884,
0.51340618, 0.45696597, 0.53756953, 0.53311051, 0.51513446,
0.48370077, 0.55220293, 0.54735972, 0.54964619, 0.48113687,
0.54010404, 0.51082335, 0.51762011, 0.49690332, 0.47472105,
0.49065431, 0.41689316, 0.56405199, 0.4882696 , 0.52682448,
0.48591399, 0.50295184, 0.60120842, 0.51617522, 0.40658693,
0.56781771, 0.61492763, 0.52000135, 0.44251528, 0.52362613,
0.53617323, 0.52644415, 0.55675933, 0.49338653, 0.49973778,
0.43464093, 0.50041838, 0.41326505, 0.50717314, 0.57902046,
0.58661785, 0.46636095, 0.47453249, 0.49514684, 0.49725683,
0.51612964, 0.50150785, 0.46914131, 0.59950553, 0.55780776,
0.52548764, 0.46012648, 0.46274524, 0.45945049, 0.45958411,
0.49571007, 0.59773427, 0.44218584, 0.52909754, 0.47783173,
0.47093312, 0.50050839, 0.49484382, 0.44588277, 0.48334843,
0.55473497, 0.58450997, 0.51046333, 0.45831258, 0.56074364,
0.42953345, 0.52390932, 0.4883246 , 0.4179659 , 0.40378093,
0.47980342, 0.51206653, 0.49401776, 0.5717336 , 0.58586622,
0.44424803, 0.46132849, 0.49828503, 0.49759926, 0.52981934,
0.46183594, 0.53167124, 0.57736354, 0.44017115, 0.47711658,
0.54400933, 0.51047602, 0.53310247, 0.521912 , 0.52196026,
0.45669692, 0.53687189, 0.46641122, 0.57882791, 0.50731345,
0.49755225, 0.47681291, 0.53587163, 0.57143839, 0.55892594,
0.54558011, 0.5112373 , 0.42577079, 0.45025764, 0.41431821,
0.4913649 , 0.45933778, 0.46314508, 0.50816717, 0.50767581,
0.43924533, 0.39440584, 0.55255438, 0.47945926, 0.5434516 ,
0.49752725, 0.47282241, 0.51322769, 0.53600364, 0.52168089,
0.52445021, 0.51475859, 0.60511272, 0.46791175, 0.55942143,
0.47491204, 0.48297982, 0.47266121, 0.51237278, 0.526572 ,
0.52900128, 0.50146413, 0.52301865, 0.50922364, 0.51750951,
0.55844339, 0.44705365, 0.53613019, 0.47337202, 0.53303916,
0.49667755, 0.60441514, 0.47341374, 0.57911445, 0.57703447,
0.47660882, 0.42214611, 0.51998454, 0.51112059, 0.48074986,
0.56466583, 0.55541125, 0.45785392, 0.43271588, 0.42288813,
0.56452885, 0.53464048, 0.60016766, 0.56045922, 0.37023561,
0.55275877, 0.5412568 , 0.43500225, 0.4717973 , 0.61145808,
0.55424162, 0.48349291, 0.57346569, 0.47740314, 0.47136564,
0.5715756 , 0.55706694, 0.51481197, 0.5174254 , 0.61102701,
0.41889314, 0.57279104, 0.49406349, 0.61903096, 0.50033106,
0.48511142, 0.49920322, 0.46290422, 0.46756176, 0.49235902,
0.49121748, 0.47286772, 0.54346361, 0.51612786, 0.40318796,
0.52794925, 0.54577571, 0.50402512, 0.51573393, 0.51810928,
0.50936374, 0.54029437, 0.49925074, 0.48249048, 0.42399465,
0.48616641, 0.46088399, 0.53894915, 0.51514487, 0.35575783,
0.44204467, 0.51241799, 0.5030408 , 0.45732213, 0.44887015,
0.48604953, 0.45094338, 0.45195624, 0.60023841, 0.49248947,
0.46466858, 0.66213072, 0.60652458, 0.56788437, 0.44666837,
0.46714585, 0.45637174, 0.51150499, 0.5122396 , 0.58823217,
0.5419413 , 0.45092006, 0.51446394, 0.47154113, 0.5717748 ,
0.48375882, 0.46637239, 0.65501911, 0.50014702, 0.55175923,
0.51281522, 0.45876994, 0.50687323, 0.53524651, 0.51178685,
0.54880718, 0.48109719, 0.53582889, 0.5750204 , 0.52703347,
0.42254709, 0.53213322, 0.52498272, 0.57021306, 0.52115583,
0.56457826, 0.45552434, 0.48812571, 0.46339706, 0.51705401,
0.46832403, 0.50174467, 0.46000171, 0.44690444, 0.39471536,
0.4897697 , 0.58852813, 0.57565495, 0.5582874 , 0.48431371,
0.45098509, 0.5366909 , 0.56668477, 0.44455347, 0.53811711,
0.53197849, 0.37736416, 0.56642719, 0.49960658, 0.48237147])
type(masses1)
numpy.ndarray
plt.hist(masses1);
plt.hist(masses2);
plt.hist(masses1, range=(0,2), bins=100);
plt.hist(masses2, range=(0,2), bins=100);
(masses1 + masses2).shape
(1000,)
masses = np.concatenate((masses1,masses2))
labels1 = np.ones(1000)
# labels1.shape
labels2 = np.ones(1000)*2
labels = np.concatenate([labels1,labels2])
masses.shape
(2000,)
plt.hist(masses, bins=100,range=(0,2));
import pandas as pd
df = pd.DataFrame(masses, columns=["mass"])
df
mass | |
---|---|
0 | 0.480860 |
1 | 0.395298 |
2 | 0.492078 |
3 | 0.536107 |
4 | 0.478890 |
... | ... |
1995 | 1.194978 |
1996 | 0.897115 |
1997 | 0.851234 |
1998 | 1.288519 |
1999 | 0.456174 |
2000 rows × 1 columns
plt.hist(df["mass"], bins=100, range=(0,2))
(array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.,
0., 0., 0., 0., 1., 0., 3., 8., 11., 35., 51.,
102., 127., 158., 158., 136., 102., 72., 34., 23., 9., 15.,
12., 15., 12., 18., 15., 22., 21., 17., 29., 32., 32.,
38., 35., 41., 23., 48., 42., 48., 45., 36., 37., 43.,
39., 26., 28., 30., 21., 9., 18., 23., 17., 22., 10.,
14., 7., 3., 4., 6., 4., 4., 1., 3., 3., 1.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0.]),
array([0. , 0.02, 0.04, 0.06, 0.08, 0.1 , 0.12, 0.14, 0.16, 0.18, 0.2 ,
0.22, 0.24, 0.26, 0.28, 0.3 , 0.32, 0.34, 0.36, 0.38, 0.4 , 0.42,
0.44, 0.46, 0.48, 0.5 , 0.52, 0.54, 0.56, 0.58, 0.6 , 0.62, 0.64,
0.66, 0.68, 0.7 , 0.72, 0.74, 0.76, 0.78, 0.8 , 0.82, 0.84, 0.86,
0.88, 0.9 , 0.92, 0.94, 0.96, 0.98, 1. , 1.02, 1.04, 1.06, 1.08,
1.1 , 1.12, 1.14, 1.16, 1.18, 1.2 , 1.22, 1.24, 1.26, 1.28, 1.3 ,
1.32, 1.34, 1.36, 1.38, 1.4 , 1.42, 1.44, 1.46, 1.48, 1.5 , 1.52,
1.54, 1.56, 1.58, 1.6 , 1.62, 1.64, 1.66, 1.68, 1.7 , 1.72, 1.74,
1.76, 1.78, 1.8 , 1.82, 1.84, 1.86, 1.88, 1.9 , 1.92, 1.94, 1.96,
1.98, 2. ]),
<BarContainer object of 100 artists>)