In this notebook, we perform exploratory data analysis in preparation for tomorrow's k-means clustering. The goal is to look for associations in floating-point data, which might represent clusters.

In [2]:
import matplotlib.pyplot as plt
import numpy as np
import warnings
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
from sklearn.model_selection import train_test_split, cross_val_score

import os

os.chdir("/home/wln/Documents/python_programs/Astronomy_Datasets")
s = pd.read_csv("sloan_survey.csv")

This is where we import the libraries we need to perform the rest of our analyisis, as well as collecting our data from the Sloan survey csv file.

In [5]:
s.columns
Out[5]:
Index(['objid', 'ra', 'dec', 'u', 'g', 'r', 'i', 'z', 'run', 'rerun', 'camcol',
       'field', 'specobjid', 'class', 'redshift', 'plate', 'mjd', 'fiberid'],
      dtype='object')
In [6]:
s.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10000 entries, 0 to 9999
Data columns (total 18 columns):
 #   Column     Non-Null Count  Dtype  
---  ------     --------------  -----  
 0   objid      10000 non-null  float64
 1   ra         10000 non-null  float64
 2   dec        10000 non-null  float64
 3   u          10000 non-null  float64
 4   g          10000 non-null  float64
 5   r          10000 non-null  float64
 6   i          10000 non-null  float64
 7   z          10000 non-null  float64
 8   run        10000 non-null  int64  
 9   rerun      10000 non-null  int64  
 10  camcol     10000 non-null  int64  
 11  field      10000 non-null  int64  
 12  specobjid  10000 non-null  float64
 13  class      10000 non-null  object 
 14  redshift   10000 non-null  float64
 15  plate      10000 non-null  int64  
 16  mjd        10000 non-null  int64  
 17  fiberid    10000 non-null  int64  
dtypes: float64(10), int64(7), object(1)
memory usage: 1.4+ MB

Here we observe that we have 10 floating point columns, and seven integer columns. 5 of the floating point columns handle the spectral qualities of the image, and two handle right ascension and declination, respectively. There is also a column for redshift and two for id values. The integer columns relate to CCD information.

In [10]:
print(s['run'].unique())
print(len(s['run'].unique()))
[ 752  756  308  727  745 1035 1045 1140 1231 1332 1334 1302 1239 1119
 1331 1345 1350 1404 1412 1336 1402 1411 1356]
23

There were 23 different imaging runs represented in this sample of 10000 objects

In [15]:
print(s['rerun'].unique())
[301]

Only one of the imaging runs was rerun.

In [17]:
print(s['camcol'].unique())
[4 2 1 5 6 3]

There were 6 different camera columns used.

In [19]:
print(s['field'].unique())
print(len(s['field'].unique()))
[267 268 269 270 271 272 273 274 275 276 277 278 279 293 294 295 296 297
 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 502 503
 504 505 506 508 509 510 511 512 515 516 517 518 519 520 521 522 104 105
 110 111 112 113 114 115 116  25  26  28  29  90  91  92  93  95  74  70
  71  66 103 538 539 567 568 571 573 575 576 579 580 411 414 415 416 417
 418 420 421 422 424 425 426 427 428 430 431 432 435 437 438 439 440 442
 443 280 281 282 283 284 285 286 287 288 289 244 245 246 249 251 252 253
 254 255 256 257 258 259 260 261 262 263 314 315 316 318 319 320 321 322
 323 324 325 326 523 524 525 526 527 528 529 530 531 581 583 584 585 591
 607 608 167 169 536 540 563 569 570 577 588 590 598 602 606 205 446 197
 199 200 201 202 203 207 208 209 210 211 213 214 215 216 217 218 219 220
 290 291 292 221 222 223 224 225 226 227 444 445 448 451 452 453 454 455
 456 457 458 459 460 461 463 464 465 466 467 469 317 447 532 534 535 537
 544 559 560 561 562 564 565 566 572 574 587 533 541 542 543 545 546 102
 107 108 117 118 119 120 121 122 125 126 127 128 129 228 229 230 265 266
 327 329 330 331 333 334 335 336 338 339 340 341 343 344 345 346 347 348
 349 185 186 187 189 192 193 195 196 198 206 212 231 232 233 234 235 236
 237 238 239 240 241 242 470 471 474 475 479 480 481 482 483 484 485 486
 487 488 489 490 491 492 493 494 593 595 596 597 600 605 609 163 165 247
 248 250 547 549 550 551 552 553 554 555 556 557 558 138 139 140 141 142
 143 144 145 146 147 148 151 152 153 154 155 156 158 161 162 328 332 342
 350 351 130 131 132 133 134 135 136 137 337 352 353 355 356 357 358 360
 361 362 363 364 365 366 367 368 495 496 497 498 499 500 501 507 513 264
 164 166 168 170 171 172 173 174 175 177 178 184 123 124 149 150 582 586
 589 592 594 599 601 243 354 369 370 371 372 578 373 374 375 376 377 378
 379 380 381 190 191 194  11  12  13  15  16  17  18  19 359  47  14 157
 159 604  46 382 383 384 385 386 387 388 389 391 393 394 395 603 610 611
 612 613 614 615 616 617 618 619 620 621 622 623 624 625  80  82  84  85
  86  88  89  94  97  98 548 188  33  23  32 160 179 180 181 182  20  21
  22  24  27  52  53  54 390 392 396 176 183 626 627 628 631 632 633 634
 635 636 637 638 639 640 642 643 644 645 646 648 649 650 652 653 654 655
 656 657 659 204 441  30  31  34  35  36  37  38 399 413 419 423 429 661
 662 663 664 665 666 667 668 669 670 671 673 674 675 676 677 679 680 681
 682 683 397 398 400 401 402  55  56  57  58  59  60  62  63  64  65  67
  68  69  72  75  76  77  78  81  83 433 434 436  39 630 762 763 764 765
 766 767  61  40  41  42  43  48  49  51 449 641 647 651 660 672 678 684
 686 687 688 689 690 692 694 696 697 698 699 700 701 703 704 705 707 710
 711  44  45  50 685 691 693 695 702 709 407 410 412  99 100 101 106 109
 450 403 404 408 409  96 405 462 468  79  87 472 473 476 477 478 768  73
 406]
703

There were 703 fields in this run.

In [21]:
plt.figure()
sns.scatterplot(x='ra',y='redshift',data=s)
Out[21]:
<Axes: xlabel='ra', ylabel='redshift'>

In this plot of right ascension vs. redshift, we see that there are very few objects with a redshift greater than three, and potential clusters may exist on this graph.

In [23]:
plt.figure()
sns.scatterplot(x='dec',y='redshift', data=s)
Out[23]:
<Axes: xlabel='dec', ylabel='redshift'>

We see similar features in this plot of declination vs. redshift.

In [24]:
plt.figure()
sns.scatterplot(x='ra', y='dec', data=s)
Out[24]:
<Axes: xlabel='ra', ylabel='dec'>

This is a plot of declination vs right ascension. There are two large clusters of objects, as can be seen in the left of the graph.

In this analysis, three clusters appear to exist in all three graphs. Hence, a value of n_clusters = 3 will start tomorrow's k-means clustering.

In [ ]: